'How to set GL codes on a Sales Invoice in Microsoft Dynamics GP?
I'm using Microsoft Dynamics GP 2015. We have a C# .Net project to create a sales invoice through web services. Accounting has the following request: "We would like to code the revenue for {an item} to GL code xx-xx-xxxx." Looking at the code for creating a sales invoice, I don't see anywhere to set a GL code. I suggested GL codes might be set on an item in GP, but was told to "see if the distribution or account codes can be set at creation time." Is there anyway to set the GL code on a sales invoice? If so, what's the code for setting a GL code?
Here's the code I'm modifiying:
private string createGPSalesInvoice(ItemReceived itemsReceived, DateTime salesOrderDate)
{
CompanyKey companyKey;
companyKey = new CompanyKey();
Context context;
SalesInvoice salesInvoice;
SalesDocumentTypeKey salesInvoiceType;
CustomerKey customerKey;
customerKey = new CustomerKey();
BatchKey batchKey;
SalesInvoiceLine salesInvoiceLine;
ItemKey invoiceItem;
Quantity invoiceCount;
Policy salesInvoiceCreatePolicy;
salesInvoiceCreatePolicy = new Policy();
string salesInvoiceNumber = "";
try
{
// 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.Id = xxx;
// Set up the context object
context.OrganizationKey = (OrganizationKey)companyKey;
// Create a sales invoice object
salesInvoice = new SalesInvoice();
// Create a sales document type key for the sales invoice
salesInvoiceType = new SalesDocumentTypeKey();
salesInvoiceType.Type = SalesDocumentType.Invoice;
// Populate the document type key for the sales invoice
salesInvoice.DocumentTypeKey = salesInvoiceType;
// Create a customer key
customerKey.Id = xxx;
// Set the customer key property of the sales invoice
salesInvoice.CustomerKey = customerKey;
salesInvoice.PostedDate = parms.endDate;
// Create a batch key
batchKey = new BatchKey();
batchKey.Id = xxx;
// Set the batch key property of the sales invoice object
salesInvoice.BatchKey = batchKey;
// Create a sales invoice line to specify the invoiced item
salesInvoiceLine = new SalesInvoiceLine();
// Create an item key
invoiceItem = new ItemKey();
invoiceItem.Id = itemsReceived.GPPartNumber;
// Set the item key property of the sales invoice line object
salesInvoiceLine.ItemKey = invoiceItem;
// Create a sales invoice quatity object
invoiceCount = new Quantity();
invoiceCount.Value = itemsReceived.Quantity;
// Set the quantity of the sales invoice line object
salesInvoiceLine.Quantity = invoiceCount;
MoneyAmount unitCost = new MoneyAmount()
{
Value = itemsReceived.CostEach
};
salesInvoiceLine.UnitPrice = unitCost;
// Create an array of sales invoice lines
// Initialize the array with the sales invoice line object
SalesInvoiceLine[] invoiceLines = { salesInvoiceLine };
// Add the sales invoice line array to the sales line object
salesInvoice.Lines = invoiceLines;
try
{
// Get the create policy for the sales invoice object
salesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesInvoice", context);
}
catch (Exception ex)
{
throw ex;
}
try
{
// Create the sales invoice
wsDynamicsGP.CreateSalesInvoice(salesInvoice, context, salesInvoiceCreatePolicy);
}
catch (Exception ex)
{
throw ex;
}
//CREATE A RESTRICION OF THE BATCH ID TO FIND THE SALES DOC JUST CREATED
LikeRestrictionOfstring batchKeyRestriction = new LikeRestrictionOfstring();
batchKeyRestriction.EqualValue = batchKey.Id;
//CREATE SEARCH CRITERIA
SalesDocumentCriteria salesDocumentCriteria = new SalesDocumentCriteria();
salesDocumentCriteria.BatchId = batchKeyRestriction;
try
{
SalesDocumentSummary[] salesDocumentSummary = wsDynamicsGP.GetSalesDocumentList(salesDocumentCriteria, context);
salesInvoiceNumber = salesDocumentSummary.FirstOrDefault().Key.Id;
}
catch (Exception ex)
{
throw ex;
}
// Close the service
if (wsDynamicsGP.State != CommunicationState.Faulted)
{
wsDynamicsGP.Close();
}
return salesInvoiceNumber;
}
catch (Exception ex)
{
throw ex;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
