Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

Dynamics GP Web Services: adding distribution lines Payables Transaction Entry

Posted on by 215

I'm trying to figure out how to add distribution lines to the Payables Transaction Entry screen.  I can add the record, but I can't seem to figure out how to override the default distribution lines for debit and credit via the web services.  What I would like to do is set the Purchase Amount, to 100, and then distribute the purch lines to two lines for 50 dollars.  So the grid would contain our credit for 100, then two purch lines for 50 each, with different account codes.  Here is my code so far, I am having trouble with getting the right type for the Amount fields for credit and debit, but I think I might still be missing somethings.  It would be great if I could find some example code to do what I want?  Here is my code so far.  Thank you.

       private void button6_Click(object sender, EventArgs e)

       {

           CompanyKey companyKey;

           Context context;

           PayablesDocumentKey invoiceKey;

           BatchKey batchKey;

           VendorKey vendorKey;

           PayablesInvoice payablesInvoice;

           Policy payablesInvoiceCreatePolicy;

           // Create an instance of the service

           DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

           // Create a context with which to call the service

           context = new Context();

           // Specify which company to use (sample company)

           companyKey = new CompanyKey();

           companyKey.Id = (-1);

           // Set up the context object

           context.OrganizationKey = (OrganizationKey)companyKey;

           // Create a payables document key object to identify the payables invoice

           invoiceKey = new PayablesDocumentKey();

           invoiceKey.Id = "00000000000001550";

           // Create a batch key

           batchKey = new BatchKey();

           batchKey.Id = "PAYABLES BATCH";

           // Create a vendor key

           vendorKey = new VendorKey();

           vendorKey.Id = "ADVANCED0001";

           // Create a money amount object for the transaction

           MoneyAmount purchaseAmount = new MoneyAmount();

           purchaseAmount.Currency = "USD";

           purchaseAmount.Value = 250m;

           // Create a payables invoice object

           payablesInvoice = new PayablesInvoice();

           payablesDistribution = new PayablesDistribution();

           DistributionTypeKey disTypeKey = new DistributionTypeKey();

           disTypeKey.Id = 6;

           GLAccountNumberKey gKey = new GLAccountNumberKey();

           gKey.Id = "600-5100-00";

           Amount creditAmount = new Amount();

           //creditAmount = (Amount)250;

           Amount debitAmount = new Amount();

           payablesDistribution.DistributionTypeKey = disTypeKey;

           payablesDistribution.GLAccountKey = gKey;

           payablesDistribution.CreditAmount = creditAmount;

           payablesDistribution.DebitAmount = debitAmount;

           // Populate the invoice properties

           payablesInvoice.Key = invoiceKey;

           payablesInvoice.BatchKey = batchKey;

           payablesInvoice.VendorKey = vendorKey;

           payablesInvoice.VendorDocumentNumber = "DOCUMENT 10";

           payablesInvoice.PurchasesAmount = purchaseAmount;

           // 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();

           }

           MessageBox.Show("done.");

       }

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics GP Web Services: adding distribution lines Payables Transaction Entry

    Hi Sekar

    To avoid default distribution, you have to override the default behavior of the create method

    you can see how to do it in the following post. I used it and it's worked fine for me.

    community.dynamics.com/.../119262.aspx

  • SekarGP Profile Picture
    SekarGP 1,145 on at
    RE: Dynamics GP Web Services: adding distribution lines Payables Transaction Entry

    Hi Moon,

    Thanks great effort..

    (How to avoid Default distribution)

    I have used your code, its working but the default distribution also inserting, i dont want to insert default distibution, our own distribution only have to insert, please help.

    Thanks in Advance

    Sekar V

  • Verified answer
    Moon Profile Picture
    Moon 215 on at
    RE: Dynamics GP Web Services: adding distribution lines Payables Transaction Entry

    I found out how and I hope this helps someone else.  Thank you.

    private void button6_Click(object sender, EventArgs e)

           {

               CompanyKey companyKey;

               Context context;

               PayablesDocumentKey invoiceKey;

               BatchKey batchKey;

               VendorKey vendorKey;

               PayablesInvoice payablesInvoice;

               Policy payablesInvoiceCreatePolicy;

               // Create an instance of the service

               DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

               // Create a context with which to call the service

               context = new Context();

               // Specify which company to use (sample company)

               companyKey = new CompanyKey();

               companyKey.Id = (-1);

               // Set up the context object

               context.OrganizationKey = (OrganizationKey)companyKey;

               // Create a payables document key object to identify the payables invoice

               invoiceKey = new PayablesDocumentKey();

               invoiceKey.Id = "00000000000001550";

               // Create a batch key

               batchKey = new BatchKey();

               batchKey.Id = "PAYABLES BATCH";

               // Create a vendor key

               vendorKey = new VendorKey();

               vendorKey.Id = "ADVANCED0001";

               // Create a money amount object for the transaction (Purchase Amount)

               MoneyAmount purchaseAmount = new MoneyAmount();

               purchaseAmount.Currency = "USD";

               purchaseAmount.Value = 250m;

               // setup my credit and debit values

               MoneyAmount creditAmount = new MoneyAmount();

               Amount aCredit = new Amount();

               creditAmount.Currency = "USD";

               creditAmount.Value = 100m;

               aCredit = creditAmount;

               MoneyAmount debitAmount = new MoneyAmount();

               Amount aDebit = new Amount();

               debitAmount.Currency = "USD";

               debitAmount.Value = 100m;

               aDebit = debitAmount;

               // Create a payables invoice object

               payablesInvoice = new PayablesInvoice();

               PayablesDistribution[] distributions = new PayablesDistribution[2];

               distributions[0] = new PayablesDistribution();

               distributions[1] = new PayablesDistribution();

               DistributionTypeKey disTypeKey = new DistributionTypeKey();

               disTypeKey.Id = 6;

               GLAccountNumberKey gKey = new GLAccountNumberKey();

               gKey.Id = "600-5100-00";

               GLAccountNumberKey g2Key = new GLAccountNumberKey();

               g2Key.Id = "000-1100-00";

               distributions[0].CompanyKey = companyKey;

               distributions[0].DistributionTypeKey = disTypeKey;

               distributions[0].GLAccountKey = gKey;

               distributions[0].DebitAmount = aDebit;

               distributions[1].CompanyKey = companyKey;

               distributions[1].DistributionTypeKey = disTypeKey;

               distributions[1].GLAccountKey = g2Key;

               distributions[1].CreditAmount = aCredit;

               // Populate the invoice properties

               payablesInvoice.Key = invoiceKey;

               payablesInvoice.BatchKey = batchKey;

               payablesInvoice.VendorKey = vendorKey;

               payablesInvoice.VendorDocumentNumber = "DOCUMENT 10";

               payablesInvoice.PurchasesAmount = purchaseAmount;

               payablesInvoice.Distributions = distributions;

               // 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();

               }

               MessageBox.Show("done.");

           }

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans