Thursday, July 2, 2020

Data Exporting to XML file using X++ in ax 2012



Welcome to Dynamics world.Today i would like to post Data export process.


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

static void exportingxml(Args _args)
{
    XmlDocument doc;
    XmlElement nodeXml;
    XmlElement nodeTable;
    XmlElement nodeId;
    XmlElement nodeName;
    XmlElement nodeCollectionType;
    XmlAttribute nodeType;    
    Testing testing ;

    #define.filename(@'D:\Ax\AnyNew.xml')
    doc = XmlDocument::newBlank();
    nodeXml = doc.createElement('xml');
    doc.appendChild(nodeXml);

    while select RecId,AccountName,AccountNum,PlayerType from testing
    {
    nodeTable = doc.createElement(tableStr(testing));
    nodeTable.setAttribute(fieldStr(testing, RecId),int642str(testing.RecId));
    nodeXml.appendChild(nodeTable);


    nodeName = doc.createElement(fieldStr(testing,AccountName));
    nodeName.appendChild(doc.createTextNode(testing.AccountName));
    nodeTable.appendChild(nodeName);

    nodeId = doc.createElement(fieldStr(testing,AccountNum));
    nodeId.appendChild(doc.createTextNode(testing.AccountNum));
    nodeTable.appendChild(nodeId);

    nodeCollectionType = doc.createElement(fieldStr(testing,PlayerType));
    nodeCollectionType.appendChild(doc.createTextNode(enum2str(testing.PlayerType)));
    nodeTable.appendChild(nodeCollectionType);

    }
    doc.save(#filename);
    info(strFmt('file is created', #filename));
}


Result in Info log:







Output:

                                                

Keep Daxing!!

For Import Process Refer to Below Link:

No comments:

Post a Comment