Thursday, July 2, 2020

Data Import from XML file into Ax 2012 using X++


Hi guys, the last  post is about  data export. Today we are going to learn about Data Import process and we are also passing Enum values into ax table.

Write this code in job and change according to your requirement.

static void readXMLFile()
{
    Testing testing;    // Table declaration 
    // Class declarations
    XmlDocument doc;
    XmlNodeList data;
    XmlElement nodeTable;
    XmlElement nodeId;
    XmlElement nodeName;
    XmlElement nodeCollectionType;
    PlayerType type;//enum declaration 
    

    #define.filename(@'D:\Ax\AnyNew.xml')
    doc = XmlDocument::newFile(#filename);
    data = doc.selectNodes('//'+tableStr(testing));
    nodeTable = data.nextNode();
    while (nodeTable)
    {
        nodeId = nodeTable.selectSingleNode(fieldStr(testing, AccountNum));
        nodeName = nodeTable.selectSingleNode(fieldStr(testing, AccountName));
        nodeCollectionType = nodeTable.selectSingleNode(fieldstr(testing, PlayerType));// enum value
        
        ttsBegin;
            testing.AccountNum= nodeId.text();
            testing.AccountName= nodeName.text();
            testing.PlayerType = str2enum(type,nodeCollectionType.text());//convert string to enum 
            testing.insert();
        ttsCommit;

        info(strFmt("%1-%2 ,%3",nodeId.text(),nodeName.text(),nodeCollectionType.text()));.// for testing
        nodeTable = data.nextNode();
    }
}


Xml Input file:



Output:



Keep Daxing.

For Export Process Refer to Below Link:

3 comments: