{"id":443,"date":"2017-08-11T08:45:48","date_gmt":"2017-08-11T06:45:48","guid":{"rendered":"http:\/\/daxvisionerp.com\/?p=443"},"modified":"2025-10-27T08:29:44","modified_gmt":"2025-10-27T08:29:44","slug":"example-csharp-code-call-aif-document-service-create","status":"publish","type":"post","link":"https:\/\/daxvisionerp.com\/home\/example-csharp-code-call-aif-document-service-create\/","title":{"rendered":"Example C# code to call AIF Document Service create"},"content":{"rendered":"<p>As part of <a href=\"http:\/\/daxvisionerp.com\/aif-document-service-code-examples\/\">AIF Document Service related examples<\/a>, here you can find an example C# code to call AIF Document Service. I would like to highlight few things in the example.<\/p>\n<ul>\n<li>Have a look at the error handling. This &#8216;catch&#8217; will display the real errors from AX even if error logging is off on the port.<\/li>\n<li>Second is that for some fields it is not enough to specifie the value, but you also need to tell it was specified. like here: \u00a0_InfoLine.Due = DateTime.Today;\u00a0_InfoLine.DueSpecified = true;<\/li>\n<li>Example for getting AX enum values:\u00a0_InfoLine.AccountType = JADSCONPOInvoiceInServiceReference.AxdEnum_LedgerJournalACType.Vend;<\/li>\n<\/ul>\n<p>So here is the whole code example:<\/p>\n<p>using System;<br \/>\nusing System.Collections.Generic;<br \/>\nusing System.Linq;<br \/>\nusing System.Text;<br \/>\nusing System.Threading.Tasks;<\/p>\n<p>namespace JADSCONPOVendInvoice<br \/>\n{<br \/>\nclass Program<br \/>\n{<br \/>\nstatic void Main(string[] args)<br \/>\n{<br \/>\ntry<br \/>\n{<br \/>\nJADSCONPOInvoiceInServiceReference.AxdEntity_JADVendNPOInvTable _InfoTable = new JADSCONPOInvoiceInServiceReference.AxdEntity_JADVendNPOInvTable();<br \/>\nJADSCONPOInvoiceInServiceReference.AxdEntity_JADVendNPOInvLine _InfoLine = new JADSCONPOInvoiceInServiceReference.AxdEntity_JADVendNPOInvLine();<\/p>\n<p>JADSCONPOInvoiceInServiceReference.AxdJADSCOVendNPOInvoice _Invoice = new JADSCONPOInvoiceInServiceReference.AxdJADSCOVendNPOInvoice();<\/p>\n<p>_Invoice.JADVendNPOInvTable = new JADSCONPOInvoiceInServiceReference.AxdEntity_JADVendNPOInvTable[1] { _InfoTable };<br \/>\n_InfoTable.TransDate = DateTime.Today;<br \/>\n_InfoTable.DocumentDate = new DateTime(2017, 8, 10);<br \/>\n_InfoTable.Description = &#8220;Document Description&#8221;;<br \/>\n_InfoTable.JournalName = &#8220;INJ&#8221;;<br \/>\n_InfoTable.JournalNum = &#8220;5&#8221;;<br \/>\n_InfoTable.SCOCaseId = 1000000;<br \/>\n_InfoTable.TransDateSpecified = true;<br \/>\n_InfoTable.DocumentDateSpecified = true;<br \/>\n_InfoTable.SCOCaseIdSpecified = true;<\/p>\n<p>_InfoTable.JADVendNPOInvLine = new JADSCONPOInvoiceInServiceReference.AxdEntity_JADVendNPOInvLine[1] { _InfoLine };<br \/>\n_InfoLine.AccountType = JADSCONPOInvoiceInServiceReference.AxdEnum_LedgerJournalACType.Vend;<br \/>\n_InfoLine.DimAccountNum = &#8220;V000001&#8221;;<br \/>\n_InfoLine.SupplierName = &#8220;Supplier name&#8221;;<br \/>\n_InfoLine.DocumentNum = &#8220;Document number&#8221;;<\/p>\n<p>_InfoLine.AmountCurCredit = 5000;<br \/>\n_InfoLine.AmountCurDebit = 0;<br \/>\n_InfoLine.TaxAmount = 100;<br \/>\n_InfoLine.GrossAmount = 5100;<br \/>\n_InfoLine.Approved = JADSCONPOInvoiceInServiceReference.AxdExtType_Approved.Yes;<br \/>\n_InfoLine.TaxCode = &#8220;TaxGroup1_TAXItemGroup1&#8221;;<\/p>\n<p>_InfoLine.DimCostCenter = &#8220;0001&#8221;;<br \/>\n_InfoLine.DimEmployee = &#8220;00000001&#8221;;<br \/>\n_InfoLine.DimPurpose = &#8220;Purpose1;<br \/>\n_InfoLine.DimSite = &#8220;Site1&#8221;;<\/p>\n<p>_InfoLine.Due = DateTime.Today;<br \/>\n_InfoLine.Invoice = &#8220;LineLevelInvoiceId1&#8221;;<\/p>\n<p>_InfoLine.Payment = &#8220;Payment1Id&#8221;;<br \/>\n_InfoLine.VATNumJournal = &#8220;VATNum1&#8221;;<\/p>\n<p>_InfoLine.AccountTypeSpecified = true;<br \/>\n_InfoLine.AmountCurCreditSpecified = true;<br \/>\n_InfoLine.AmountCurDebitSpecified = true;<br \/>\n_InfoLine.TaxAmountSpecified = true;<br \/>\n_InfoLine.GrossAmountSpecified = true;<br \/>\n_InfoLine.ApprovedSpecified = true;<br \/>\n_InfoLine.DueSpecified = true;<\/p>\n<p>JADSCONPOInvoiceInServiceReference.JADSCOVendNPOInvoiceServiceClient _Client = new JADSCONPOInvoiceInServiceReference.JADSCOVendNPOInvoiceServiceClient(\/*_serviceEndpointName*\/);<\/p>\n<p>JADSCONPOInvoiceInServiceReference.CallContext _callContext = new JADSCONPOInvoiceInServiceReference.CallContext();<\/p>\n<p>_callContext.Company = &#8220;CMP1&#8221;;<\/p>\n<p>JADSCONPOInvoiceInServiceReference.EntityKey[] entityKeys = _Client.create(_callContext, _Invoice);<\/p>\n<p>}<br \/>\ncatch (System.ServiceModel.FaultException&lt;JADSCONPOInvoiceInServiceReference.AifFault&gt; aifFaults)<br \/>\n{<br \/>\nJADSCONPOInvoiceInServiceReference.InfologMessage[] infologMessageList = aifFaults.Detail.InfologMessageList;<\/p>\n<p>foreach (JADSCONPOInvoiceInServiceReference.InfologMessage infologMessage in infologMessageList)<br \/>\n{<\/p>\n<p>Console.WriteLine(&#8220;Exception: &#8221; + infologMessage.Message + &#8220;\\n&#8221;);<br \/>\n}<\/p>\n<p>Console.WriteLine(&#8220;\\nPress any key to quit.\\n&#8221;);<br \/>\nConsole.ReadKey();<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As part of AIF Document Service related examples, here you can find an example C# code to call AIF Document Service. I would like to highlight few things in the example. Have a look at the error handling. This &#8216;catch&#8217; will display the real errors from AX even if error logging is off on the [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"1080","footnotes":""},"categories":[1],"tags":[],"class_list":["post-443","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/posts\/443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/comments?post=443"}],"version-history":[{"count":1,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/posts\/443\/revisions"}],"predecessor-version":[{"id":1410,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/posts\/443\/revisions\/1410"}],"wp:attachment":[{"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/media?parent=443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/categories?post=443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/tags?post=443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}