Sunday, 26 April 2015

Object 'clrobject' Could not Be Created While Activating Account Structure - Axapta 2012

Hello Guys ...!

Issue :

While activating Account structure in Ax 2012 R2 getting bellow error

object 'clrobject' could not be created


Solution :

->  Go to the Control Panel/Administrative Tools and check the Microsoft Dynamics AX 2012       Server Configuration and note if you have 'Enable the hot-swapping of assemblies for each                  development session' activated.

-> Restart AOS and do Generate Incremental CIL from AOT



@Rahul Talasila

Saturday, 25 April 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, 21 April 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, 15 April 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, 14 April 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

Adding a newline into a string in C# and X++

Below is the sample code we can use for  adding a newline after every occurrence of "@" symbol in the string in C#   using System...