Wednesday, January 28, 2015

Create New XmL file through AX 2012 X++

// Create New XmL file through AX 2012

XmlDocument doc;
    XmlElement nodeXml;
    XmlElement nodeTable;
    XmlElement nodeAccount;
    XmlElement nodeName;
    CustTable custTable;
    #define.filename(@'C:\Temp\accounts.xml')
    doc = XmlDocument::newBlank();
    nodeXml = doc.createElement('xml');
    doc.appendChild(nodeXml);
    while select RecId, AccountNum from custTable
    {
        nodeTable = doc.createElement(tableStr(CustTable));
        nodeTable.setAttribute(fieldStr(CustTable, RecId),int642str(custTable.RecId));
        nodeXml.appendChild(nodeTable);
        nodeAccount = doc.createElement(fieldStr(CustTable, AccountNum));
        nodeAccount.appendChild(doc.createTextNode(custTable.AccountNum));
        nodeTable.appendChild(nodeAccount);
        nodeName = doc.createElement("Name");
        nodeName.appendChild(doc.createTextNode(CustTable::find(custTable.AccountNum).name()));
        nodeTable.appendChild(nodeName);
    }
    doc.save(#filename);
    info(strFmt("File %1 created.", #filename));

Read XML file in ax 2012 R2 X++

// Read XML file in ax 2012 R2  

static void Readxmldoc(Args _args)
{
    XmlDocument doc;
    str 10000   note;   
    #define.filename(@'C:\sanPayslip.xml')
   
    doc = XmlDocument::newFile(#filename);   
    note = doc.toString();   
    info(note);
}

Source:

XmlDocument doc;
    XmlNodeList data;
    XmlElement nodeTable;
    XmlElement nodeAccount;
    XmlElement nodeName;
    XmlElement nodeRecId;
    XMLTestTable    xmlTable;
    #define.filename(@'C:\Temp\accounts.xml')
    doc = XmlDocument::newFile(#filename);
    data = doc.selectNodes('//'+tableStr(CustTable));
    nodeTable = data.nextNode();
    delete_from xmlTable;
    while (nodeTable)
    {
        nodeAccount = nodeTable.selectSingleNode(fieldStr(CustTable, AccountNum));
        xmlTable.AccountNum = nodeAccount.text();
        xmlTable.Name = CustTable::find(nodeAccount.text()).name();
        //nodeRecId = nodeTable.selectSingleNode(fieldStr(CustTable, RecId));
        //xmlTable.CustRecId = str2int64(nodeRecId.text());
        info(strFmt("%1 - %2",nodeAccount.text(),nodeRecId.text()));
        //xmlTable.insert();
        nodeTable = data.nextNode();
    }

Upload data from Excel in D365FO X++

 Action Menu Item: SAN_UploadExcelData Object type: Class Object: <Controller class name> Label: <> Class: Controller class clas...