Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

GP Webservices CreatePayablesInvoice -How do I add Tax Lines to my PayablesInvoice ?

Posted on by 10

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

 //Tax lines
                XmlNodeList taxnodes = xmlDoc.DocumentElement.SelectNodes(xMLPMTransactionLineTaxNode);
                List<PayablesTax> payableTaxes = new List<PayablesTax>();
             
              foreach (XmlNode taxnode in taxnodes)
                {
                    PayablesTax payableTax = new PayablesTax();
                   
                   //THE BELOW TAX DETAIL ASSIGNMENT IS GIVING THE ERROR.
                    TaxDetailKey taxDetailKey = new TaxDetailKey();
                    taxDetailKey.Id = taxnode.SelectSingleNode("TAXDTLID").InnerText;
                    payableTax.Key.TaxDetailKey = taxDetailKey; //THIS LINE IS THROWING THE NULL OBJECT REFERENCE ERROR
                   

                    MoneyAmount taxAmount = new MoneyAmount();
                    taxAmount.Currency = "AUD";
                    taxAmount.Value = Convert.ToDecimal(taxnode.SelectSingleNode("TAXAMNT").InnerText);
                   payableTax.TaxAmount = taxAmount;
                   
                   MoneyAmount purchasetaxAmount = new MoneyAmount();
                    purchasetaxAmount.Currency = "AUD";
                    purchasetaxAmount.Value = Convert.ToDecimal(taxnode.SelectSingleNode("TDTTXPUR").InnerText);
                    payableTax.PurchasesTaxAmount = purchasetaxAmount;
                   
                    MoneyAmount purchasetotalAmount = new MoneyAmount();
                    purchasetotalAmount.Currency = "AUD";
                    purchasetotalAmount.Value = Convert.ToDecimal(taxnode.SelectSingleNode("TXDTTPUR").InnerText);
                    payableTax.TotalAmount = purchasetotalAmount;
                   
                   payableTaxes.Add(payableTax);

                }
                payablesInvoice.Taxes = payableTaxes.ToArray();
              

                // Get the create policy for payables invoices
                payablesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation( "CreatePayablesInvoice", context);
                // Create the payables invoice
                wsDynamicsGP.CreatePayablesInvoice(payablesInvoice, context, payablesInvoiceCreatePolicy);
                // Close the service
                if (wsDynamicsGP.State != CommunicationState.Faulted)
                {
                    wsDynamicsGP.Close();
                }

From the above code, THE BELOW TAX DETAIL ASSIGNMENT IS GIVING THE ERROR.

                    TaxDetailKey taxDetailKey = new TaxDetailKey();
                    taxDetailKey.Id = taxnode.SelectSingleNode("TAXDTLID").InnerText;
                    payableTax.Key.TaxDetailKey = taxDetailKey; //THIS LINE IS THROWING THE NULL OBJECT REFERENCE ERROR
Not sure I have to use 'PayablesTax' to assign tax to PayablesInvoice?
Below is the XMl
<?xml version="1.0"?>
-
<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>
Categories:
  • Suggested answer
    Isaac Olson Profile Picture
    Isaac Olson on at
    RE: GP Webservices CreatePayablesInvoice -How do I add Tax Lines to my PayablesInvoice ?

    Hello, 

    To open a support case you can use the information in the following article. 

    https://community.dynamics.com/gp/b/dynamicsgp/posts/important-change-coming-to-technical-support-workflow-and-how-you-create-a-support-case

    This will lead you to the following link: https://support.microsoft.com/supportforbusiness

    Thanks!

    Isaac Olson

    Microsoft Support

  • cideve Profile Picture
    cideve 10 on at
    RE: GP Webservices CreatePayablesInvoice -How do I add Tax Lines to my PayablesInvoice ?

    Thanks Issac, Actually I want to implement the Tax detail part using .Net code ,as  suggested could you please let me know how to raise a support case ?.

  • Suggested answer
    Isaac Olson Profile Picture
    Isaac Olson on at
    RE: GP Webservices CreatePayablesInvoice -How do I add Tax Lines to my PayablesInvoice ?

    Hello, 

    I will let someone with more C# knowledge than myself chime in if they happen to see the issue with your code, but I did want to help you on the GP side at least with verifying the information from your XML and how GP will process that.   I took your XML and converted it directly to SQL so you can test executing the following and see if you receive any setup errors.   This would help you in verifying if your issue is simply with your code in Web Services or if it is related to bad data or a missing setup in your GP company. 

    -- eConnectSQL Version: 3.7.0.21 Date/Time: 2020/03/12 10:48:05
    -- From Clipboard

    SET NOCOUNT ON
    BEGIN TRANSACTION
    DECLARE @O_iErrorState INT,
    @oErrString VARCHAR(255),
    @oRptString VARCHAR(255)
    ---- taPMTransactionTaxInsert_Items

    --====================================================================
    /**/
    SET @O_iErrorState=0 -- Reset Errors
    SET @oErrString=''
    EXEC taPMTransactionTaxInsert
    @I_vVENDORID='MJC001',
    @I_vVCHRNMBR='0',
    @I_vDOCTYPE='1',
    @I_vBACHNUMB='HLPM3000-1622',
    @I_vTAXDTLID='P-GSTFS',
    @I_vTAXAMNT='0',
    @I_vTDTTXPUR='1319.8',
    @I_vTXDTTPUR='1319.8',
    @O_iErrorState=@O_iErrorState OUT, @oErrString=@oErrString OUT
    SELECT @oRptString = 'SELECT ErrorCode, SourceProc, ErrorDesc FROM DYNAMICS..taErrorCode WHERE ErrorCode IN (' + REPLACE(RTRIM('0'+@oErrString),CHAR(32), ',') + ')'
    EXEC(@oRptString)
    /**/
    ---- taPMTransactionInsert

    --====================================================================
    /**/
    SET @O_iErrorState=0 -- Reset Errors
    SET @oErrString=''
    EXEC taPMTransactionInsert
    @I_vBACHNUMB='HLPM3000-1622',
    @I_vVCHNUMWK='0',
    @I_vVENDORID='MJC001',
    @I_vDOCNUMBR='BI-7094927',
    @I_vDOCTYPE='1',
    @I_vDOCAMNT='1319.8',
    @I_vDOCDATE='2019-10-30',
    @I_vPSTGDATE='2019-10-01',
    @I_vTAXSCHID='ALL-PURCHASES',
    @I_vDUEDATE=default, -- Empty Parameter : DUEDATE
    @I_vDISCDATE=default, -- Empty Parameter : DISCDATE
    @I_vCHRGAMNT='1319.8',
    @I_vCAMTDATE=default, -- Empty Parameter : CAMTDATE
    @I_vCHEKDATE=default, -- Empty Parameter : CHEKDATE
    @I_vTRXDSCRN='Exported from Sysnet',
    @I_vMSCCHAMT='1319.8',
    @I_vTax_Date=default, -- Empty Parameter : Tax_Date
    @I_vEXPNDATE=default, -- Empty Parameter : EXPNDATE
    @I_vEXCHDATE=default, -- Empty Parameter : EXCHDATE
    @I_vCREATEDIST='1',
    @O_iErrorState=@O_iErrorState OUT, @oErrString=@oErrString OUT
    SELECT @oRptString = 'SELECT ErrorCode, SourceProc, ErrorDesc FROM DYNAMICS..taErrorCode WHERE ErrorCode IN (' + REPLACE(RTRIM('0'+@oErrString),CHAR(32), ',') + ')'
    EXEC(@oRptString)
    /**/

    IF @O_iErrorState = 0
    COMMIT TRANSACTION
    ELSE
    ROLLBACK TRANSACTION -- Simplifies re-testing

    I hope this helps, and that if there is someone in the community that is more savy with C# that they will chime in if the issue is specifically with your syntax, otherwise we could certainly dig into this further through a support case with the proper resources.  

    Thanks, 

    Isaac Olson

    Microsoft Dynamics GP Support

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans