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.

CIL generation error : The given key was not present in the dictionary.


Recently I faced this error when generating incremental IL
"CIL generation: The given key was not present in the dictionary."

The quick way to fix this is to check the CIL log file, generally located at "C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin\XppIL\Dynamics.Ax.Application.dll.log"

Here you will find the AOT object for which the CIL generator found the error. Compile that object, fix the error and then regenerate the IL.

Before generating IL make sure that there are no compilation errors in the code.

Cheers!

Duplicate type with name 'Dynamics.Ax.application.' in assembly 'Dynamics.Ax.application,

To resolve this issue perform the following steps:

  1. Full compile AX
  2. Stop the AOS
  3. Truncate the SysXPPAssembly table in SQL (the table is used to contain the assemblies and to share between multiple AOS instances)
  4. Delete the DLL and netmodule files in your AOS's bin\xppIL directory(C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin\XppIL directory).
  5. Restart the AOS
  6. Perform full CIL generation

Sunday, May 10, 2015

AIF value substitution maps



By creating value substitution mapping, you can define how values are replaced when data is processed in a pipeline. Each lookup table(substitution map) can act on only one data type. For example, for the ExternalItemId data type, you can create entries that replace several part numbers with part account numbers.

Goto System administration > Setup > Services and Application Integration Framework and open Value substitution maps.





Each entry in a lookup table defines a relationship between an internal value and an external value. The way that values are substituted depends on the direction of the document transfer.

For inbound transfers, the value that you enter in the Internal value field replaces the value that you enter in the External value field.
For outbound transfers, the value that you enter in the External value field replaces the value that you enter in the Internal value field.

Cheers! :)

Thursday, May 7, 2015

How to configure automatic shutdown for all online users

Go to Menu –> Tools –> Option as shown in the screen below.




Go to General -> Interface options -> Security and specify automatic shutdown time, screen shot below.





Wednesday, May 6, 2015

Bypass validation of DocumentHash when updating a record using AIF


Here is the code to bypass validation of DocumentHash when updating a record using AIF

docVersionXml = _axInternalBase.parm_DocumentHash();

if (docVersionXml)
{
docVersionDb = document.getRecordHash();

    if (docVersionDb != docVersionXml)
    {
throw error("@SYS106156");
    }
}
else
{
throw error(strfmt("@SYS26332", AxInternalBase::stripParm(methodstr(AxInternalBase, parm_DocumentHash))));
}

Enjoy!

Force Sync AOT tables through X++


Here is the code to force the database synchronization in Dynamics Ax,

static void forceSyncDB(Args _args)
{
Dictionary dict;
int idx, lastIdx, totalTables;
TableId tableId;
Application application;
SysOperationProgress progress;
StackBase errorStack;
ErrorTxt errorTxt;

application = new Application();
dict = new Dictionary();
totalTables = dict.tableCnt();
progress = new SysOperationProgress();
progress.setTotal(totalTables);
progress.setCaption(“@SYS90206″);
errorStack = new StackBase(Types::String);
lastIdx = 0;

try
{
for (idx = lastIdx+1; idx <= totalTables; idx++)
{
tableId = dict.tableCnt2Id(idx);
progress.setText(dict.tableName(tableId));
lastIdx = idx;
application.dbSynchronize(tableId, false, true, false);
progress.incCount();
}
}
catch (Exception::Error)
{
errorTxt = strFmt("Error in table '%1' (%2)", tableId, dict.tableName(tableId));
errorStack.push(errorTxt);
retry;
}

setPrefix("@SYS86407");
errorTxt = errorStack.pop();

while (errorTxt)
{
error(errorTxt);
errorTxt = errorStack.pop();
}
}

Cheers! 

Sunday, May 3, 2015

Deploy Microsoft Dynamics AX 2012 R3 on Azure

You can deploy Microsoft Dynamics AX 2012 R3 on MS Azure virtual machines. Refer to this TechNet link for more details.