Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 17314

AIF: Adding a tag at the top level for an XML interface document

$
0
0

I have a customer who has multiple legacy systems that will generate XML documents for invoices and the idea was to import these invoices as free text invoice into their Dynamics AX system. I wanted to use the Dynamics AX built in Free Text Invoice AIF document interface (CustFreeTextInvoiceService) to load these invoice into AX.

Because the customer has multiple systems that will generate the XML document, I wanted to know which system the xml document originated from. I planned to add data to the xml to identify the legacy system that the document is from with an XSLT transform that would be applied to the AIF port and then use different ports to handle the data from each system.

I wanted to add this extra field (tag) to the top level (the interface document level and not at the lower levels e.g. FreeTextInvoice tag and not CustInvoiceTable). This field is to be adjacent to the SenderId and DocPurpose tags.

The XML document, once modified by the XSLT transform, will look like the following with the extra tag that I have added appears at line 14:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?xmlversion="1.0"encoding="utf-8"?><Envelopexmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message"><Header><PartitionKey>initial</PartitionKey><Company>RTR</Company><Action>http://schemas.microsoft.com/dynamics/2008/01/services/FreeTextInvoiceService/create</Action></Header><Body><MessageParts><FreeTextInvoicexmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/FreeTextInvoice"><DocPurposexsi:nil="true"/><InterfaceSystem>Priarch</InterfaceSystem><SenderIdxsi:nil="true"/><CustInvoiceTable><_DocumentHashxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:nil="true"/><InterfaceDocTypexmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:nil="true"/><VAT1Amount>5</VAT1Amount><VAT1Code>STD</VAT1Code><VAT1Goods>25</VAT1Goods><DefaultDimensionxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:nil="true"/><LanguageId>en-us</LanguageId><OrderAccount>Cust_52</OrderAccount><CustInvoiceLine><DefaultDimensionxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:nil="true"/><TaxGroup>UK</TaxGroup><TaxItemGroup>STD</TaxItemGroup></CustInvoiceLine></CustInvoiceTable></FreeTextInvoice></MessageParts></Body></Envelope></xml>

 

Of course, adding the extra tag to the XML is easy. What we need to do is to make AX process the extra tag so that we can gain access to its value within the code.

Step 1:

To do this, I modified the CustFreeTextInvoice class and added the following methods:

In the ClassDeclaration:

#define.CWFInterfaceSystem('InterfaceSystem')

And then added the following two methods:

1
2
3
4
5
6
7
8
9
public InterfaceSystem parmInterfaceSystem(InterfaceSystem _value =0){if(!prmisDefault(_value)){
        this.set_Attribute(#InterfaceSystem, _value);
    } 
    return this.get_Attribute(#InterfaceSystem);
}

 

1
2
3
4
publicboolean existsInterfaceSystem(){return this.exists(#InterfaceSystem);
}

 

Step 2:

I added similar methods to the AxdFreeTextInvoice class:

In the ClassDeclaration:

InterfaceSystem          interfaceSystem;

And then added the following two method:

1
2
3
4
5
6
public InterfaceSystem parmInterfaceSystem(InterfaceSystem _interfaceSystem = interfaceSystem){
    interfaceSystem = _interfaceSystem;
 
    return interfaceSystem;
}

 

Step 3:

Now getting the value from the InterfaceSystem tag is very simple. I just modified the “prepareForSaveExtended” method like the following:

caseclassNum(AxCustInvoiceTable):
   axCustInvoiceTable = _axBcStack.top();	
 
   ...
 
   if(_recordProcessingContext == AxdRecordProcessingContext::BeforeAnyChildRecordsProcessed){
       axCustInvoiceTable.parmIntSys(this.parmInterfaceSystem());
   }

…and now my code can tell which of the customer systems the invoice came from.


Viewing all articles
Browse latest Browse all 17314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>