Saturday, April 25, 2015

Copy Data From One Table To Another Table By Using buf2buf- Ax 2012

Hello Guys...!

Some times we get requirement like , we have to copy data from one table to other table .

For that we use buf2buf()  Global method. This method we can use if our second table fields Id's are same as First table field Id's.

If not then we need to do some changes in buf2buf() method

Example :

-> Here i duplicated "InventTable" and named "CopyInventTable"
->I'm copying data from InventTable to CopyInventTable by using Buf2Buf method

Step 1:

Go to Class-> Global-> buf2buf() method and paste below code

static void buf2buf(Common  _from, Common  _to)
{
    DictTable   dictTableFrom   = new DictTable(_from.TableId);
    DictTable   dictTableTo     = new DictTable(_to.TableId);
    DictField   dictFieldFrom;
    FieldId     fieldIdFrom     = dictTableFrom.fieldNext(0);
    FieldId     fieldIdTo
    ;


    while (fieldIdFrom && ! isSysId(fieldIdFrom))
    {
        dictFieldFrom   = new DictField(_from.TableId, fieldIdFrom);


        if(dictFieldFrom)
        {
            fieldIdTo = dictTableTo.fieldName2Id(dictFieldFrom.name());


            if(fieldIdTo)
                _to.(fieldIdTo) = _from.(fieldIdFrom);
        }


        fieldIdFrom = dictTableFrom.fieldNext(fieldIdFrom);
    }
}

Step 2 :

Paste the below code in AOT -> Jobs and new Job


static void CopyData(Args _args)
{
    InventTable inventTable;
    CopyInventTable copyInventTable ;
    ;
 
    while select inventTable
    {
         buf2Buf(inventTable ,copyInventTable );
         copyInventTable .insert();
    }
    info("Done");
}




That's It.


@Rahul Talasila

Tuesday, April 21, 2015

Update Vendor Contact Information - In Ax 2012

Hello Guys ..!

Here i'm sharing code to update vendor contact details (phone, fax, email) in  ax 2012.

Note :
-> create temp table (VendorImportTmp ) with VendorId,phone,fax,email fields
-> Use CSV file

static void Vendor_Contactsupdate(Args _args)
{
    CommaIO                             csvFile;
    container                           readCon;
    counter                             icount,inserted;
    container                           line;
    Dialog                              dialog;
    DialogField                         dfFileName;
    FileName                            fileName;
    VendAccount                         vendNum;
    DirOrganization                     dirOrganization;
    LogisticsLocation                   logisticsLocation;
    LogisticsPostalAddress              logisticsPostalAddress;
    LogisticsElectronicAddress          logisticsElectronicAddressPhone, logisticsElectronicAddressfax, LogisticsElectronicAddressEmail;
    VendTable                           vendTable;
    VendorImportTmp                     vendorImportTmp;
    DirPartyTable                       dirPartyTable, dirPartyTableLocal;
 

    inserted=0;
    #File
    dialog = new Dialog("Select File to Import");
    dfFileName = dialog.addField(extendedTypeStr(FileNameOpen));
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    vendNum ="";
    if (dialog.run())
    {
    filename =  dfFileName.value();
    }
    csvFile = new CommaIO(filename, 'r');
       if (csvFile)
        {
            ttsBegin;
            while (csvFile.status() == IO_Status::OK)
            {
                readCon = csvFile.read();
                    if (readCon)
                    {
                            vendorImportTmp.clear();
                            vendorImportTmp.RecId =0;
                            vendorImportTmp.AccountNum            = conPeek(readCon,1);
                            vendorImportTmp.LocaterPhone           = conPeek(readCon,2);
                            vendorImportTmp.LocaterFax             = conPeek(readCon,3);
                            vendorImportTmp.LocaterEmail          = conPeek(readCon,4);
                            vendorImportTmp.ContactDescription = conPeek(readCon,5);
                            dirPartyTable = DirPartyTable::findRec(VendTable::find(vendorImportTmp.AccountNum).Party);
                            dirOrganization = dirPartyTable;
                                vendorImportTmp.Name = VendTable::find(vendorImportTmp.AccountNum).name();
                                            logisticsLocation = LogisticsLocation::create(vendorImportTmp.Name, NoYes::Yes);
                                        //Party location
                                        DirParty::addLocation(dirOrganization.RecId, logisticsLocation.RecId, true, true, false, [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Business).RecId]);

                                        //Location
                                        logisticsLocation = LogisticsLocation::create('Electronic address', NoYes::Yes);

                                        //Party location
                                        DirParty::addLocation(dirOrganization.RecId, logisticsLocation.RecId, false, true, false);

                                        if(vendorImportTmp.LocaterPhone)
                                        {
                                            logisticsElectronicAddressPhone.clear();
                                            logisticsElectronicAddressPhone.initValue();
                                            logisticsElectronicAddressPhone.Location = logisticsLocation.RecId;
                                            logisticsElectronicAddressPhone.Type = LogisticsElectronicAddressMethodType::Phone;
                                            logisticsElectronicAddressPhone.Locator = vendorImportTmp.LocaterPhone;
                                            if(vendorImportTmp.ContactDescription == "")
                                            {
                                                vendorImportTmp.ContactDescription = "Phone";
                                            }
                                            logisticsElectronicAddressPhone.Description = vendorImportTmp.ContactDescription;
                                            logisticsElectronicAddressPhone.IsPrimary = NoYes::Yes;

                                            if (logisticsElectronicAddressPhone.validateWrite())
                                            {
                                                logisticsElectronicAddressPhone.insert();
                                            }
                                        if(vendorImportTmp.LocaterFax)
                                        {
                                            logisticsElectronicAddressfax.clear();
                                            logisticsElectronicAddressfax.initValue();
                                            logisticsElectronicAddressfax.Location = logisticsLocation.RecId;
                                            logisticsElectronicAddressfax.Type = LogisticsElectronicAddressMethodType::Fax;
                                            logisticsElectronicAddressfax.Locator = vendorImportTmp.LocaterFax;
                                             if(vendorImportTmp.ContactDescription == "")
                                            {
                                                vendorImportTmp.ContactDescription = "fax";
                                            }
                                            logisticsElectronicAddressfax.Description = vendorImportTmp.ContactDescription;
                                            logisticsElectronicAddressfax.IsPrimary = NoYes::Yes;
                                            if (logisticsElectronicAddressfax.validateWrite())
                                            {
                                                logisticsElectronicAddressfax.insert();
                                            }
                                        }
                                        if(vendorImportTmp.LocaterEmail)
                                        {
                                            LogisticsElectronicAddressEmail.clear();
                                            LogisticsElectronicAddressEmail.initValue();
                                            LogisticsElectronicAddressEmail.Location = logisticsLocation.RecId;
                                            LogisticsElectronicAddressEmail.Type = LogisticsElectronicAddressMethodType::Email;
                                            LogisticsElectronicAddressEmail.Locator = vendorImportTmp.LocaterEmail;
                                            LogisticsElectronicAddressEmail.Description = vendorImportTmp.ContactDescription;
                                            if (LogisticsElectronicAddressEmail.validateWrite())
                                            {
                                               LogisticsElectronicAddressEmail.insert();
                                            }
                                        select forUpdate dirPartyTableLocal where dirPartyTableLocal.RecId == dirPartyTable.RecId;
                                        if(dirPartyTableLocal)
                                        {
                                            dirPartyTableLocal.PrimaryContactPhone = logisticsElectronicAddressPhone.RecId;
                                            dirPartyTableLocal.PrimaryContactFax = logisticsElectronicAddressfax.RecId;
                                            dirPartyTableLocal.PrimaryContactEmail = LogisticsElectronicAddressEmail.RecId;
                                            dirPartyTableLocal.update();
                                        }
                                         
                                            inserted++;
                                        }
                        }

                    }
            }

    }
    info(strFmt("%1 Records inserted Succesfully",inserted));
    ttsCommit;
}


@Rahul Talasila

Wednesday, April 15, 2015

Filter Records on Item Lookup Through X++ - Ax 2012

Hello Guys ..!

Here i'm sharing code for filtering records in a look up. In this example I'm filtering the items which are stopped and displaying only available  items.

Write the below code in formDatasource ->Field->methods-> Override LookUp() method

Code:
---------

public void lookup(FormControl _formControl, str _filterStr)
{
 
       // super(_formControl, _filterStr);
        Query query = new Query();
        QueryBuildDataSource qbds;
        QueryBuildDataSource QbdsJoin;

        // Instantiate sysTableLookup object using table which will provide the visible fields
        SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(InventTable), _formControl);
        ;

        // Create the query.
        qbds= query.addDataSource(tableNum(InventTable));
        qbds.addRange(fieldNum(InventTable, ItemId));

        //Join Table
        QbdsJoin= qbds.addDataSource(tableNum(InventItemInventSetup));
        QbdsJoin.relations(true);
        QbdsJoin.joinMode(JoinMode::InnerJoin);
        QbdsJoin.addRange(fieldNum(InventItemInventSetup, ItemId));
        QbdsJoin.addRange(fieldNum(InventItemInventSetup, Stopped)).value(enum2Value(NoYes::No));
        // Set the query to be used by the lookup form
        sysTableLookup.parmQuery(query);

        // Specify the fields to show in the form.
        sysTableLookup.addLookupfield(fieldNum(InventTable, ItemId), true);
        sysTableLookup.addLookupfield(fieldNum(InventTable, NameAlias), true);
   sysTableLookup.addLookupMethod(tablemethodstr(InventTable, Alle_Unit));
   sysTableLookup.addLookupfield(fieldNum(InventTable, ItemType),true);
        // Perform the lookup
        sysTableLookup.performFormLookup();
}




@Rahul Talasila

Tuesday, April 14, 2015

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond - In Axapta 2012

Hello Guys...!

Some time we get below error while running SSRS reports in Ax 2012.

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond


Reason : 

Dynamics AX 2012 uses SQL Server Reporting Services for rendering reports. SSRS gets the data from AOS by using a custom SSRS Extension that uses WCF to communicate with AOS.


Depending on the size of the data and the complexity of the report, it might take a long time for the report to execute, resulting in various timeout and other thresholds being hit, which might cause the report rendering to fail.

Solution :

Below are the steps With Example:

In Ax 2012 Project management and accounting -> Reports - > Actual Transactions -> Project Actual Transactions.

While running this report i got the same error.

Solution :

1) To extend the SRSReportDataProviderPreProcess class instead of SRSReportDataProviderBase class
     
    //class ProjListProjProfitLossProjDP extends SRSReportDataProviderBase
     class ProjListProjProfitLossProjDP extends SrsReportDataProviderPreProcess

2) Set the user connection in processReport method after the contract method initialization
        
// Set the user connection to use on table.
// This is required to ensure that createdTransactionId of inserted record is different than default transaction.
projListProjProfitLossTmp.setConnection(this.parmUserConnection());

3) To change the property of the temp table like below,
    a) Table Type = Regular
    b) Created by = Yes
    c) Created Transaction Id = Yes

4) Open the Report in visual studio and refresh the Data set (make sure createTransactionId field is appear in the Data Set)

5) Save and deploy the Report.

6) Do the Incremental CIL

7) Restart SSRS service


@Rahul Talasila

Wednesday, March 4, 2015

Field token Fields!MyNewField.Value is invalid. Could not find the identifier- In Ax 2012 SSRS Reports

Hello Guys...!

Error:

some times when deploying or building SSRS report in visual studio we get below error.

Field token Fields!MyNewField.Value is invalid. Could not find the identifier


Solution :

-> Refresh Data-sets
-> Check the parameters what are available in your report.
->Check your design items whether they are using available parameters or not
-> If not find the design item that uses unavailable parameter and remove it .



@Rahul Talasila

Saturday, February 28, 2015

Error while setting server report parameters. Error message: The DefaultValue expression for the report parameter ‘AX_CompanyName’ contains an error: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (rsRuntimeErrorInExpression) - In Ax 2012

Error :

Error while setting server report parameters. Error message: The DefaultValue expression for the report parameter ‘AX_CompanyName’ contains an error: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (rsRuntimeErrorInExpression)

Solution :


C:\Program Files\Microsoft SQL Server\MSRS11.TEST\Reporting Services\ReportServer

open "rssrvpolicy" in NotePad

and go to

<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="Execution" Name="Report_Expressions_Default_Permissions" Description="This code group grants default permissions for code in report expressions and Code element. ">


and paste the below code and save.


<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="Report_Expressions_Default_Permissions" Description="This code group grants default permissions for code in report expressions and Code element. ">




Thats It..



@Rahul Talasila

Sunday, February 22, 2015

A call to the Microsoft Dynamics AX SRSFrameworkService service failed. The target principal name is incorrect.

Issue :

A call to the Microsoft Dynamics AX SRSFrameworkService service failed. The target principal name is incorrect.



Solution :


Steps to resolve the issue
1.Generate full IL

open AOT and register the following services:
->SRSFrameworkService
->SSASFrameworkService


Go to Services Group node and auto deploy the following service groups:
BIServices
UserSessionService




That's It..



@Rahul Talasila

What is the primary purpose of using a Solution in Microsoft Power Platform & ALM?

As organizations embrace low-code development with Microsoft Power Platform , it becomes essential to manage and govern apps, flows, and dat...