Hi,
We are developing C# console application to call GP API. I am calling the method CreatePayablesInvoice to create payables Invoice. However I want to assign Tax lines to this.
I am trying to assign taxDetailKey to payableTax.Key.TaxDetailKey ,but am getting null object reference error. Please need help to fix this .
Below are the steps am following and I have provided the related XML also
1)// Create a payables invoice object
payablesInvoice = new PayablesInvoice();
2)// Populate the invoice properties
payablesInvoice.Key = invoiceKey;
payablesInvoice.BatchKey = batchKey;
payablesInvoice.VendorKey = vendorKey; ...etc
3)//Setting the tax lines
XmlNodeList taxnodes = xmlDoc.DocumentElement.SelectNodes(xMLPMTransactionLineTaxNode);
List<PayablesTax> payableTaxes = new List<PayablesTax>();
{
taxDetailKey.Id = taxnode.SelectSingleNode("TAXDTLID").InnerText;
payableTax.Key.TaxDetailKey = taxDetailKey; //THIS LINE IS THROWING THE NULL OBJECT REFERENCE ERROR
taxAmount.Currency = "AUD";
taxAmount.Value = Convert.ToDecimal(taxnode.SelectSingleNode("TAXAMNT").InnerText);
purchasetaxAmount.Currency = "AUD";
purchasetaxAmount.Value = Convert.ToDecimal(taxnode.SelectSingleNode("TDTTXPUR").InnerText);
purchasetotalAmount.Currency = "AUD";
purchasetotalAmount.Value = Convert.ToDecimal(taxnode.SelectSingleNode("TXDTTPUR").InnerText);
}
// Get the create policy for payables invoices
payablesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation( "CreatePayablesInvoice", context);
wsDynamicsGP.CreatePayablesInvoice(payablesInvoice, context, payablesInvoiceCreatePolicy);
if (wsDynamicsGP.State != CommunicationState.Faulted)
{
wsDynamicsGP.Close();
}
From the above code, THE BELOW TAX DETAIL ASSIGNMENT IS GIVING THE ERROR.
taxDetailKey.Id = taxnode.SelectSingleNode("TAXDTLID").InnerText;
payableTax.Key.TaxDetailKey = taxDetailKey; //THIS LINE IS THROWING THE NULL OBJECT REFERENCE ERROR
<eConnect
xmlns:dt="urn:schemas-microsoft-com:datatypes">
-
<PMTransactionType>
-
<taPMTransactionTaxInsert_Items>
-
<taPMTransactionTaxInsert>
<VENDORID>MJC001</VENDORID>
<VCHRNMBR>0</VCHRNMBR>
<DOCTYPE>1</DOCTYPE>
<BACHNUMB>HLPM3000-1622</BACHNUMB>
<TAXDTLID>P-GSTFS</TAXDTLID>
<TAXAMNT>0</TAXAMNT>
<TDTTXPUR>1319.8</TDTTXPUR>
<TXDTTPUR>1319.8</TXDTTPUR>
</taPMTransactionTaxInsert>
</taPMTransactionTaxInsert_Items>
-
<taPMTransactionInsert>
<BACHNUMB>HLPM3000-1622</BACHNUMB>
<VCHNUMWK>0</VCHNUMWK>
<VENDORID>MJC001</VENDORID>
<DOCNUMBR>BI-7094927</DOCNUMBR>
<DOCTYPE>1</DOCTYPE>
<DOCAMNT>1319.8</DOCAMNT>
<DOCDATE>2019-10-30</DOCDATE>
<PSTGDATE>2019-10-01</PSTGDATE>
<TAXSCHID>ALL-PURCHASES</TAXSCHID>
<DUEDATE/>
<DISCDATE/>
<CHRGAMNT>1319.8</CHRGAMNT>
<CAMTDATE/>
<CHEKDATE/>
<TRXDSCRN>Exported from Sysnet</TRXDSCRN>
<MSCCHAMT>1319.8</MSCCHAMT>
<Tax_Date/>
<EXPNDATE/>
<EXCHDATE/>
<CREATEDIST>1</CREATEDIST>
</taPMTransactionInsert>
</PMTransactionType>
</eConnect>