Monday, September 20, 2021

Create Xml using X++ - D365 FnO

 class My_XMLCreate

{

    /// <summary>

    /// Runs the class with the specified arguments.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

    public static void main(Args _args)

    {

        XmlDocument xdoc;

        XmlElement  xElement;

        XmlElement  xTable, xNodeAccount, xNodeName;

        MainAccount mainAccount;


        #define.filename(@'C:\Temp\accounts.xml');


        xdoc = XmlDocument::newBlank();

        xElement =xdoc.createElement('xml');

        xdoc.appendChild(xElement);


        while select RecId, mainAccountId, Name from mainAccount

        {

            xTable = xdoc.createElement(tableStr(MainAccount));

            xTable.setAttribute(fieldStr(MainAccount, RecId), int642Str(mainAccount.RecId));

            xElement.appendChild(xTable);

            

            xNodeAccount = xdoc.createElement(fieldStr(MainAccount, MainAccountId));

            xNodeAccount.appendChild(xdoc.createTextNode(MainAccount.MainAccountId));

            xTable.appendChild(xNodeAccount);

            

            xNodeName = xdoc.createElement(fieldStr(MainAccount, Name));

            xNodeName.appendChild(xdoc.createTextNode(mainAccount.Name));

            xTable.appendChild(xNodeName);

        }


        xdoc.save(#filename);

        Info(strFmt("File %1 created", #filename));



    }


}

No comments:

Post a Comment

Copying and Auto populating financial dimension from inventSite X++

 APPROACH 1 //calling method DimensionAttributeValueSetStorage  valueStorage = this.getDefaultDimension(inventsite); purchTable.defaultdimen...