Monday, 5 March 2018

How to Export Data into the XML using X++ in AX 2012.

To Export the data into the XML file using X++ use the bellow code.

public void xmlGeneration(Args _args)
{
    XmlDocument doc;
    XmlElement nodeXml;
    XmlElement nodeTable;
    XmlElement nodeAccount;
    XmlElement nodeName;
    CustTable   custTable;
    #define.filename(@'C:\\Users\nagan020\Desktop\productsXML.xml')
    ;
    doc = XmlDocument::newBlank();
    nodeXml = doc.createElement('xml');

    doc.appendChild(nodeXml);
     //Determines the runtime
    if (xSession::isCLRSession())
    {
        info('Running in a CLR session.');
    }
    else
    {
        info('Running in an interpreter session.');

        //Determines the tier
        if (isRunningOnServer())
        {
            info('Running on the AOS.');
        }
        else
        {
            info('Running on the Client.');
        }
    }

    while select custTable
    {
        nodeTable = doc.createElement(tablestr(CustTable));
        nodeTable.setAttribute(fieldstr(CustTable, RecId),int2str(custTable.RecId));
        nodeXml.appendChild(nodeTable);
        nodeAccount = doc.createElement(fieldstr(CustTable, AccountNum));
        nodeAccount.appendChild(doc.createTextNode(custTable.AccountNum));
        nodeTable.appendChild(nodeAccount);
        nodeName = doc.createElement(fieldstr(CustTable,CustGroup));
        nodeName.appendChild(doc.createTextNode(custTable.CustGroup));
        nodeTable.appendChild(nodeName);
      }
    doc.save(#filename);
    info(strFmt("File %1 created.", #filename));
}

Hope this will help...
Happy Daxing...

No comments:

Post a Comment