Home > X++ stuffs > How to Display Table,Query field value in Xml.

How to Display Table,Query field value in Xml.

 

Hi Everyone,

In table, query, view we have a system method as xml () which is used to display field value in Xml.  The structure of table/query is created as Xml. This method gives you the feasibility of populating the fields directly in xML without actually using the xML Classes available in AX.

Please find the following examples below:

Using Table:

static void TableFieldsAsxML(Args _args)
{
    #define.CustAccountNum(‘4000’)
    #AOT
    #define.xmlFileName(‘.xml’)

    CustTable   custTable;
    XmlDocument xmlDocument;
    str         _xml;
    ;

    xmlDocument = new XmlDocument();

    select firstonly custTable
        where custTable.AccountNum == #CustAccountNum;

    _xml = custTable.xml(1);
    xmlDocument.loadXml(_xml);
    xmlDocument.save(WinApi::getTempPath() +
                                     #AOTDelimiter +
                                     strins(strrem(xmlDocument.name(), ‘#’), #xmlFileName, strlen(xmlDocument.name()) + 1));
}

 
Using Query:
 

static void QueryAsxML(Args _args)
{
    #AOT
    #define.xmlFileName(‘.xml’)
    #define.CustAccountNum(‘4000’)

    Query                q;
    QueryRun             qr;
    QueryBuildDataSource qbd;
    QueryBuildRange      qbr;
    XmlDocument          xmlDocument;
    str                  _xml;
    ;

    q = new Query();
    qbd = q.addDataSource(tableNum(CustTable));
    qbr = qbd.addRange(fieldNum(CustTable, AccountNum));
    qbr.value(#CustAccountNum);
    qbd.addSortField(fieldNum(CustTable, Name));
    qr = new QueryRun(q);
    xmlDocument = new XmlDocument();
    _xml = q.xml(1);
    xmlDocument.loadXml(_xml);
    xmlDocument.save(WinApi::getTempPath() +
                                     #AOTDelimiter + 
                                     strins(strrem(xmlDocument.name(), ‘#’), #xmlFileName, strlen(xmlDocument.name()) + 1));
}

33232781.jpg

 
This way you can use the system xml() function view a given file in xml.
Advertisements
Categories: X++ stuffs
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: