Thursday, June 4, 2015

Dynamics AX AIF Services Error: "Type 'http://schemas.microsoft.com/dynamics/2008/01/sharedtypes:AxdExtType_CFPSId_BR' is not declared."

You might get this or similar error when you activate inbound/outbound port or view document schema from data policies, To resolve this error all you need to do is
refresh AIF Services as shown below,


If you are still getting this error this means there are some errors in one or more objects related to the service you are trying to use, To get rid of this perform following steps

1) Identify objects that are causing this issue - Compile all tables that are in service query datasouce and ax* classes related to the services.
2) Fix error(s).
3) Refresh AIFservices as mentioned above.

Cheers!

Wednesday, June 3, 2015

Wildcard search in Dynamics AX



If you have to add functionality similar to wildcard like operator.

Select * from VendTable where VendTable.Name is like ‘%Vendor XYZ%’

You can use static functions SysQuery::valueLike and SysQuery::ValueLikeAfter.I used these functions in datasource ExecuteQuery() method

QueryBuildRange vendorFilter = SysQuery::findOrCreateRange(PGDFileline_q.dataSourceTable(tablenum(vendTable)),fieldNum(VendTable,AccountNum));

if (vendTxt.text()!="")
{
vendorFilter.value(SysQuery::valueLikeAfter(vendTxt.text()));
}
else
{
vendorFilter.value(SysQuery::valueUnlimited());
}

super();

Tuesday, June 2, 2015

Dynamics AX 2012: Delete operating unit

AX throws an error "This organisation participates in one or more hierarchies and cannot be deleted" when you try to delete an operating unit if it is used in one or more organizational hierarchy.

Here is a way to delete operating unit,

1) Table: OmOperatingUnit - get recid using name or name alias(this recid will be used in next three steps).

2) Table: DimensionAttributeValue -> Field: EntityInstance -> search recid in this field and delete record.

3) Table: OMHierarchyRelationship -> Field: ChildOrganisation ->  search recid in this field and delete record.

4) Table: OMOperatingUnit -> Field: recid -> search recid and delete record.

Wednesday, May 20, 2015

Importing warehouses from CSV file

Here is the code for importing warehouses from excel file,

static void InventWarehouseImportFromExcel(Args _args)
{
    SysExcelApplication   application;
    SysExcelWorkbooks   workbooks;
    SysExcelWorkbook     workbook;
    SysExcelWorksheets   worksheets;
    SysExcelWorksheet     worksheet;
    SysExcelCells              cells;
    COMVariantType        type;
    FileName                     filename;
    int                                 row =0 ;
    str                                 ProductName;
    str                 _              ProductCode;
 
    InventSiteId                 inventSiteId;
    InventLocationName   inventLocationName;
    InventLocationId         inventLocationId;
    InventLocation            inventLocation;
 
 
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
 
    //specify the file path that you want to read
    filename = "C:\\ sample path \\test.xlsx"; //add file path here.
 
    try
    {
        //  Adds the file as the first document in the collection.
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }
 
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);   // represents the current worksheet in my case it's (1)
    cells = worksheet.cells();
 
    // Fetches data from each cell that contains data.
    do
    {
        row++;
 
        inventSiteId = cells.item(row, 1).value().bStr();
        InventLocationId = cells.item(row, 3).value().bStr();
        InventLocationName = cells.item(row, 4).value().bStr();
 
        ttsBegin;
 
        inventLocation.InventLocationId = InventLocationId;
        inventLocation.Name = InventLocationName;
        inventLocation.InventSiteId = inventSiteId;
        inventLocation.insert();
 
        ttsCommit;
 
        type = cells.item(row+1, 1).value().variantType();
    }
    // Runs until the COMVarientType doesnot contains a data field.
    while (type != COMVariantType::VT_EMPTY);
 
    // Closes the Instance of Excel.
    application.quit();
}

Importing sites from excel file

Recently i created a job to import sites from excel file, here is the code.

    static void InventSiteImportFromExcel(Args _args)
    {
        SysExcelApplication   application;
        SysExcelWorkbooks   workbooks;
        SysExcelWorkbook     workbook;
        SysExcelWorksheets   worksheets;
        SysExcelWorksheet     worksheet;
        SysExcelCells              cells;
        COMVariantType        type;
        FileName                     filename;
        int                                 row =0 ;
        str                                 ProductName;
        str                 _              ProductCode;
 
        InventSite                    inventSite;
        InventSiteId                 inventSiteId;
        InventSiteName           inventSiteName;
ReqSitePolicy   reqSitePolicy;

        application = SysExcelApplication::construct();
        workbooks = application.workbooks();
 
        //specify the file path that you want to read
        filename = "C:\\sample path \\test.xlsx"; // add file path here.
 
        try
        {
            //  Adds the file as the first document in the collection.
            workbooks.open(filename);
        }
        catch (Exception::Error)
        {
            throw error("File cannot be opened.");
        }
 
        workbook = workbooks.item(1);
        worksheets = workbook.worksheets();
        worksheet = worksheets.itemFromNum(1);   // represents the current worksheet in my case it's (1)
        cells = worksheet.cells();
 
        // Fetches data from each cell that contains data.
        do
        {
            row++;
 
            inventSiteId = cells.item(row, 1).value().bStr();
            inventSiteName   = cells.item(row, 2).value().bStr();
 
            ttsBegin;
 
            inventSite.SiteId = inventSiteId;
            inventSite.Name = inventSiteName;
            inventSite.insert();
 
            ttsCommit;
 
            type = cells.item(row+1, 1).value().variantType();
        }
        // Runs until the COMVarientType doesnot contains a data field.
        while (type != COMVariantType::VT_EMPTY);
 
        // Closes the Instance of Excel.
        application.quit();

//site will not be visible on WHM->Setup->WH setup-> sites
       // unless you add recoelds in ReqSitePolicy table
insert_recordset reqSitePolicy (InventSiteId)
select SiteId from InventSite;
    }

Cheers!

Wednesday, May 13, 2015

Dynamics AX 2012 R2 ERD's

Here is the link for "AxErd" website that hosts entity relationship (ER) diagrams for core tables of the application modules in Microsoft Dynamics AX 2012 R2.

Monday, May 11, 2015

Cleanup User cache data (delete AUC file)

AUC means application Unicode object cache. The .auc file contains cached data for the Microsoft Dynamics AX Windows client application on the client computer.To delete AUC file
follow following step.

1. Stop AOS.
2. Delete the .auc file from users\\Appdata\ folder
3. Restart AOS.