Monday, November 24, 2014

Importing Sales order XML using X++

The following job will create Sales order using Document service through X++ code.

static void JobTestWebService_ImportXml(Args _args)
{
    //feed the xml that was modified after exporting through exportxml job
    XmlDocument xml = XmlDocument::newFile(@'C:\SORequest.xml');
    AxdSalesOrder salesOrder;

    try
    {
        salesOrder = new AxdSalesOrder();
        salesOrder.create(xml.xml(),  new AifEndPointActionPolicyInfo(), new AifConstraintList());
    }
    catch
    {
        throw error('Error in document service');
    }
    info(strFmt('Sales order created'));
}

Sample XML File

<?xml version="1.0" encoding="utf-8" ?>
<SalesOrder xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesOrder">
<SalesTable class="entity">
  <CustAccount>1204</CustAccount>
  <DeliveryDate>2011-10-11</DeliveryDate>
  <ReceiptDateRequested>2011-11-11</ReceiptDateRequested>
  <PurchOrderFormNum>ABC-98654</PurchOrderFormNum>
<TableDlvAddr class="entity">
<Address>KEVIN DAVIS 13075 MANCHESTER RD STE 228.A  DES PERES, MO 631311878 </Address>
<City>DES PERES</City>
<CountryRegionId>USA</CountryRegionId>
<County>JEFFERSON</County>
<ISOcode>US</ISOcode>
<LocationName>KEVIN DAVIS</LocationName>
<State>MO</State>
<Street>13075 MANCHESTER RD STE 228.A </Street>
<ValidFrom>2014-11-11T00:00:00Z</ValidFrom>
<ValidTo>2014-11-11T00:00:00Z</ValidTo>
<ZipCode>631311878</ZipCode>
</TableDlvAddr>
  <SalesLine class="entity">
<ItemId>0001</ItemId>
<SalesQty>20</SalesQty>
<SalesPrice>82.25</SalesPrice>
<SalesUnit>Pcs</SalesUnit>
  </SalesLine>
</SalesTable>

</SalesOrder>

No comments:

Post a Comment