web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Dynamics GP Web Services: adding distribution lines Payables Transaction Entry

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Verified answer
    Moon Profile Picture
    215 on at

    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.");

           }

  • SekarGP Profile Picture
    1,145 on at

    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

  • Community Member Profile Picture
    on at

    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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans