Saturday, April 16, 2016

CREATE XML : EXPORT DATA INTO XML : MICROSOFT DYNAMICS AX 2012

CREATE XML : EXPORT DATA INTO XML : MICROSOFT DYNAMICS AX 2012

class CreateXmlFile
{
}
public static void main(Args _args)
{
XmlDocument doc;
XmlElement nodeXml;
XmlElement nodeTable; XmlElement nodeAccount; XmlElement nodeName; MainAccount mainAccount;
#define.filename(@'C:\accounts.xml')
doc         = XmlDocument::newBlank();
nodeXml = doc.createElement('xml');
doc.appendChild(nodeXml);
while select RecId, MainAccountId, Name from mainAccount
{
nodeTable = doc.createElement(tableStr(MainAccount));
nodeTable.setAttribute(fieldStr(MainAccount, RecId), int642str(mainAccount.RecId));
nodeXml.appendChild(nodeTable);
nodeAccount = doc.createElement( fieldStr(MainAccount, MainAccountId));
nodeAccount.appendChild( doc.createTextNode(mainAccount.MainAccountId));
nodeTable.appendChild(nodeAccount);
nodeName = doc.createElement( fieldStr(MainAccount, Name));
nodeName.appendChild( doc.createTextNode(mainAccount.Name));
nodeTable.appendChild(nodeName);
}
doc.save(#filename);
info(strFmt("File %1 created.", #filename));
}

Run the class.

The XML file accounts.xml will be created in the specified folder.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...