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