Quantcast
Viewing all articles
Browse latest Browse all 59474

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

       }


Viewing all articles
Browse latest Browse all 59474

Trending Articles