SBX - Search With Button

SBX - Forum Post Title

Reading values from xml file

Microsoft Dynamics AX Forum

BASMA asked a question on 14 Sep 2018 4:51 AM
My Badges

Question Status

Verified

Hi,

I have this xml File:

I have table EUKSecurityTreeNode that have relation with another table EUKSecurityForm,EUKSecurityMenus et EUKSecurityMenuItems :

EUKSecurityTreeNode.euksecurityform=EUKSecurityForm.recid

EUKSecurityTreeNode.euksecuritymenu=EUKSecurityMenus.recid

EUKSecurityTreeNode.euksecuritymenuItems=EUKSecurityMenuItems.recid

I want when I go to the second node from "EUKSecurityTreeNode" I automatically go to the second node of the other tables "EUKSecurityForm",...to get the exact value.

Reply
Martin Dráb responded on 14 Sep 2018 5:11 AM

What's the context of your question? Are you trying to import this file through DIXF, are you trying to writing some custom code or what?

Reply
BASMA responded on 14 Sep 2018 5:22 AM
My Badges

I export this file from base and I want to import it in another base.

I do this with code.

I want when I insert the values in euksecurityTreeynode,I find the corresponding values from the other tables means :

when I insert the field "euksecurityForm" in "euksecuritytreenode " i should search this vlues in the table Euksecurityform

case #EUKSecurityTreeNode :

try
{

ttsBegin;
EUKSecurityTreeNode=null;
case #EUKSecurityForm:
eukSecurityForm=eukSecurityForm::findName(nodelistrecords.item(6).innerText());

break;

case #EUKSecurityMenus:
eukSecurityMenus=eukSecurityMenus::findName(nodelistrecords.item(7).innerText());

break;

EUKSecurityTreeNode.EUKSecurityForm=eukSecurityForm.RecId;

EUKSecurityTreeNode.EUKSecurityMenus=eukSecurityMenus.RecId;
EUKSecurityTreeNode.EUKSecurityMenuItems=eukSecurityMenuItems.RecId;
EUKSecurityTreeNode.SecurityLevel = str2enum(securityLevel,nodelistrecords.item(3).innerText());
EUKSecurityTreeNode.AOTNodePath = nodelistrecords.item(0).innerText();
EUKSecurityTreeNode.EUKMatrixRoleVersion = str2int64(nodelistrecords.item(5).innerText());
EUKSecurityTreeNode.EUKMatrixRole=eukMatrixRole.RecId;
EUKSecurityTreeNode.EUKSecurityWorkflows=str2int64(nodelistrecords.item(10).innerText());
EUKSecurityTreeNode.SecurableName=nodelistrecords.item(1).innerText();
EUKSecurityTreeNode.SecurableType=str2enum(securableType,nodelistrecords.item(2).innerText());
EUKSecurityTreeNode.Type=str2enum(type,nodelistrecords.item(9).innerText());
EUKSecurityTreeNode.MatrixRole=nodelistrecords.item(11).innerText();
EUKSecurityTreeNode.EUKSecurityForm=str2int64(nodelistrecords.item(6).innerText());
EUKSecurityTreeNode.EUKSecurityMenus=str2int64(nodelistrecords.item(8).innerText());
EUKSecurityTreeNode.EUKSecurityMenuItems=str2int64(nodelistrecords.item(7).innerText());
EUKSecurityTreeNode.insert();
ttsCommit;
}
catch
{
error("@EUK481");
ttsAbort;
}
break;

Can I do this??

Reply
BASMA responded on 16 Sep 2018 11:33 AM
My Badges

Hi,

have you any idea how can I get this structure in xml file :

<EuksecurityTreeNode>

<name></name>

<type></type>

   <EukSecurityMenus>

         <name>  </name>

          <type> </type>

           .......

 </EulSecurityMenus>

</EuksecurityTreeNode>

Reply
Rustem Galiamov responded on 16 Sep 2018 5:56 PM
My Badges
Suggested Answer

Hi BASMA!

You should use XmlDocument and XmlElement classes to create XML file.

Here is an example:

static void createXMLFile(Args _args)
{
    XmlDocument doc;
    XmlElement  nodeXml;
    XmlElement  nodeTable;
    XmlElement  nodeAccount;
    XmlElement  nodeName;
    InventTable inventTable;
    Counter     test;
    #define.filename('<documents>\\test.xml')

    doc     = XmlDocument::newBlank();
    nodeXml = doc.createElement('xml');

    doc.appendChild(nodeXml);

    while select inventTable
    {
        nodeTable = doc.createElement(tablestr(inventTable));
        nodeTable.setAttribute(fieldstr(inventTable, RecId), int642str(inventTable.RecId));
        nodeXml.appendChild(nodeTable);
        nodeAccount = doc.createElement(fieldStr(inventTable, ItemId));
        nodeAccount.appendChild(doc.createTextNode(inventTable.ItemId));
        nodeTable.appendChild(nodeAccount);
        nodeName = doc.createElement(fieldStr(InventTable, NameAlias));
        nodeName.appendChild(doc.createTextNode(InventTable.NameAlias));
        nodeTable.appendChild(nodeName);
        
        test++;
        
        if (test > 10)
            break;
     }

    doc.save(#filename);
}


Reply
BASMA responded on 17 Sep 2018 3:07 AM
My Badges

Hi Rustem,

thanks for your reply but I want to display multiple tables in the same file like this:

<tableA>

<name> </name>

<type>   </type>

<tableB> //has relation with tableA

   <name>   </name>

    <source> </source>

</tableB>

<tableC> //has relaion with tableA

....

</tableC>

</tableA>

Reply
Rustem Galiamov responded on 17 Sep 2018 3:23 AM
My Badges
Suggested Answer

Just add it inside while select statement:

static void createXMLFile(Args _args)
{
    XmlDocument         doc;
    XmlElement          nodeXml;
    XmlElement          nodeTable;
    XmlElement          nodeAccount;
    XmlElement          nodeName;
    InventTable         inventTable;
    InventTableModule   inventTableModule;
    Counter             test;
    #define.filename('<documents>\\test.xml')
    
    doc     = XmlDocument::newBlank();
    nodeXml = doc.createElement('xml');

    doc.appendChild(nodeXml);

    while select inventTable
    {
        nodeTable = doc.createElement(tablestr(inventTable));
        nodeTable.setAttribute(fieldstr(inventTable, RecId), int642str(inventTable.RecId));
        nodeXml.appendChild(nodeTable);
        nodeAccount = doc.createElement(fieldStr(inventTable, ItemId));
        nodeAccount.appendChild(doc.createTextNode(inventTable.ItemId));
        nodeTable.appendChild(nodeAccount);
        nodeName = doc.createElement(fieldStr(InventTable, NameAlias));
        nodeName.appendChild(doc.createTextNode(InventTable.NameAlias));
        nodeTable.appendChild(nodeName);
        
        while select inventTableModule
            where inventTableModule.ItemId == inventTable.ItemId
        {
            nodeTable = doc.createElement(tablestr(InventTableModule));
            nodeTable.setAttribute(fieldstr(inventTableModule, RecId), int642str(inventTableModule.RecId));
            nodeXml.appendChild(nodeTable);
            nodeAccount = doc.createElement(fieldStr(inventTableModule, ModuleType));
            nodeAccount.appendChild(doc.createTextNode(enum2str(inventTableModule.ModuleType)));
            nodeTable.appendChild(nodeAccount);
            nodeName = doc.createElement(fieldStr(inventTableModule, UnitId));
            nodeName.appendChild(doc.createTextNode(inventTableModule.UnitId));
            nodeTable.appendChild(nodeName);
        }

        test++;

        if (test > 10)
            break;
     }

    doc.save(#filename);
}


Reply
BASMA responded on 17 Sep 2018 3:49 AM
My Badges

it's not the solution that I want :

I want that the node of euksecurityForm will be included in the node euksecurityTreeNode.

Reply
BASMA responded on 17 Sep 2018 3:49 AM
My Badges

it's not the solution that I want :

I want that the node of euksecurityForm will be included in the node euksecurityTreeNode.

Reply
Rustem Galiamov responded on 17 Sep 2018 4:08 AM
My Badges

So, euksecurityTreeNode and euksecurityForm need to be in the same level or not?

Reply
BASMA responded on 17 Sep 2018 4:23 AM
My Badges

I want that the euksecurityForm will be included in the node of euksecurityTreeNode:

<euksecurityTreeNode>

<euksecurityForm>

                  i want here to get the information from the table euksecurityForm which has relation with  euksecurityTreeNode

</euksecurityForm>

</euksecurityTreeNode>

Reply
Rustem Galiamov responded on 17 Sep 2018 4:38 AM
My Badges
Verified Answer

Ok. Try like this:

static void createXMLFile(Args _args)
{
    XmlDocument         doc;
    XmlElement          nodeXml;
    XmlElement          nodeTable, nodeTable2;
    XmlElement          nodeItem;
    XmlElement          nodeName;
    InventTable         inventTable;
    InventTableModule   inventTableModule;
    Counter             test;
    #define.filename('<documents>\\test.xml')
    
    doc     = XmlDocument::newBlank();
    nodeXml = doc.createElement('xml');

    doc.appendChild(nodeXml);

    while select inventTable
    join inventTableModule
        where inventTableModule.ItemId == inventTable.ItemId
           && inventTableModule.ModuleType == ModuleInventPurchSales::Sales
    {
        nodeTable = doc.createElement(tablestr(inventTable));
        nodeTable.setAttribute(fieldstr(inventTable, RecId), int642str(inventTable.RecId));
        nodeXml.appendChild(nodeTable);
        nodeItem = doc.createElement(fieldStr(inventTable, ItemId));
        nodeItem.appendChild(doc.createTextNode(inventTable.ItemId));
        nodeTable.appendChild(nodeItem);
        nodeName = doc.createElement(fieldStr(InventTable, NameAlias));
        nodeName.appendChild(doc.createTextNode(InventTable.NameAlias));
        nodeTable.appendChild(nodeName);
        
        nodeTable2 = doc.createElement(tablestr(inventTableModule));
        nodeTable2.setAttribute(fieldstr(inventTableModule, RecId), int642str(inventTableModule.RecId));
        nodeTable.appendChild(nodeTable2);
        nodeItem = doc.createElement(fieldStr(inventTableModule, ItemId));
        nodeItem.appendChild(doc.createTextNode(inventTableModule.ItemId));
        nodeTable2.appendChild(nodeItem);
        nodeName = doc.createElement(fieldStr(inventTableModule, UnitId));
        nodeName.appendChild(doc.createTextNode(inventTableModule.UnitId));
        nodeTable2.appendChild(nodeName);
        
        test++;

        if (test > 1)
            break;
     }

    doc.save(#filename);
}


Reply
BASMA responded on 17 Sep 2018 5:15 AM
My Badges

Thanks

that's what I want :)

Reply
Rustem Galiamov responded on 17 Sep 2018 4:38 AM
My Badges
Verified Answer

Ok. Try like this:

static void createXMLFile(Args _args)
{
    XmlDocument         doc;
    XmlElement          nodeXml;
    XmlElement          nodeTable, nodeTable2;
    XmlElement          nodeItem;
    XmlElement          nodeName;
    InventTable         inventTable;
    InventTableModule   inventTableModule;
    Counter             test;
    #define.filename('<documents>\\test.xml')
    
    doc     = XmlDocument::newBlank();
    nodeXml = doc.createElement('xml');

    doc.appendChild(nodeXml);

    while select inventTable
    join inventTableModule
        where inventTableModule.ItemId == inventTable.ItemId
           && inventTableModule.ModuleType == ModuleInventPurchSales::Sales
    {
        nodeTable = doc.createElement(tablestr(inventTable));
        nodeTable.setAttribute(fieldstr(inventTable, RecId), int642str(inventTable.RecId));
        nodeXml.appendChild(nodeTable);
        nodeItem = doc.createElement(fieldStr(inventTable, ItemId));
        nodeItem.appendChild(doc.createTextNode(inventTable.ItemId));
        nodeTable.appendChild(nodeItem);
        nodeName = doc.createElement(fieldStr(InventTable, NameAlias));
        nodeName.appendChild(doc.createTextNode(InventTable.NameAlias));
        nodeTable.appendChild(nodeName);
        
        nodeTable2 = doc.createElement(tablestr(inventTableModule));
        nodeTable2.setAttribute(fieldstr(inventTableModule, RecId), int642str(inventTableModule.RecId));
        nodeTable.appendChild(nodeTable2);
        nodeItem = doc.createElement(fieldStr(inventTableModule, ItemId));
        nodeItem.appendChild(doc.createTextNode(inventTableModule.ItemId));
        nodeTable2.appendChild(nodeItem);
        nodeName = doc.createElement(fieldStr(inventTableModule, UnitId));
        nodeName.appendChild(doc.createTextNode(inventTableModule.UnitId));
        nodeTable2.appendChild(nodeName);
        
        test++;

        if (test > 1)
            break;
     }

    doc.save(#filename);
}


Reply
Rustem Galiamov responded on 16 Sep 2018 5:56 PM
My Badges
Suggested Answer

Hi BASMA!

You should use XmlDocument and XmlElement classes to create XML file.

Here is an example:

static void createXMLFile(Args _args)
{
    XmlDocument doc;
    XmlElement  nodeXml;
    XmlElement  nodeTable;
    XmlElement  nodeAccount;
    XmlElement  nodeName;
    InventTable inventTable;
    Counter     test;
    #define.filename('<documents>\\test.xml')

    doc     = XmlDocument::newBlank();
    nodeXml = doc.createElement('xml');

    doc.appendChild(nodeXml);

    while select inventTable
    {
        nodeTable = doc.createElement(tablestr(inventTable));
        nodeTable.setAttribute(fieldstr(inventTable, RecId), int642str(inventTable.RecId));
        nodeXml.appendChild(nodeTable);
        nodeAccount = doc.createElement(fieldStr(inventTable, ItemId));
        nodeAccount.appendChild(doc.createTextNode(inventTable.ItemId));
        nodeTable.appendChild(nodeAccount);
        nodeName = doc.createElement(fieldStr(InventTable, NameAlias));
        nodeName.appendChild(doc.createTextNode(InventTable.NameAlias));
        nodeTable.appendChild(nodeName);
        
        test++;
        
        if (test > 10)
            break;
     }

    doc.save(#filename);
}


Reply
Rustem Galiamov responded on 17 Sep 2018 3:23 AM
My Badges
Suggested Answer

Just add it inside while select statement:

static void createXMLFile(Args _args)
{
    XmlDocument         doc;
    XmlElement          nodeXml;
    XmlElement          nodeTable;
    XmlElement          nodeAccount;
    XmlElement          nodeName;
    InventTable         inventTable;
    InventTableModule   inventTableModule;
    Counter             test;
    #define.filename('<documents>\\test.xml')
    
    doc     = XmlDocument::newBlank();
    nodeXml = doc.createElement('xml');

    doc.appendChild(nodeXml);

    while select inventTable
    {
        nodeTable = doc.createElement(tablestr(inventTable));
        nodeTable.setAttribute(fieldstr(inventTable, RecId), int642str(inventTable.RecId));
        nodeXml.appendChild(nodeTable);
        nodeAccount = doc.createElement(fieldStr(inventTable, ItemId));
        nodeAccount.appendChild(doc.createTextNode(inventTable.ItemId));
        nodeTable.appendChild(nodeAccount);
        nodeName = doc.createElement(fieldStr(InventTable, NameAlias));
        nodeName.appendChild(doc.createTextNode(InventTable.NameAlias));
        nodeTable.appendChild(nodeName);
        
        while select inventTableModule
            where inventTableModule.ItemId == inventTable.ItemId
        {
            nodeTable = doc.createElement(tablestr(InventTableModule));
            nodeTable.setAttribute(fieldstr(inventTableModule, RecId), int642str(inventTableModule.RecId));
            nodeXml.appendChild(nodeTable);
            nodeAccount = doc.createElement(fieldStr(inventTableModule, ModuleType));
            nodeAccount.appendChild(doc.createTextNode(enum2str(inventTableModule.ModuleType)));
            nodeTable.appendChild(nodeAccount);
            nodeName = doc.createElement(fieldStr(inventTableModule, UnitId));
            nodeName.appendChild(doc.createTextNode(inventTableModule.UnitId));
            nodeTable.appendChild(nodeName);
        }

        test++;

        if (test > 10)
            break;
     }

    doc.save(#filename);
}


Reply

SBX - Two Col Forum

SBX - Migrated JS