We are the getting the folowing error on deleteing the duplicate line item in invoice through the gp web service, we are passing the line sequence number :
Line cannot be deleted. Combination of SalesDocumentKey, Type, ItemKey, LineSequenceNumber, and ComponentSequenceNumber does not exist on document.
Code is as follows :
CompanyKey companyKey;
Context context;
SalesDocumentKey salesOrderKey;
SalesOrder salesOrder;
SalesOrderLine salesOrderLine;
Policy salesOrderUpdatePolicy;
SalesInvoice salesInvoice = null;
SalesInvoiceLine salesInvoiceLine = null;
// Create an instance of the web service
DynamicsGP wsDynamicsGP = new DynamicsGP();
// Be sure the default credentials are used
wsDynamicsGP.UseDefaultCredentials = true;
// Create a context with which to call the web 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;
// context.CultureName = "en-US";
// Create a sales document key
salesOrderKey = new SalesDocumentKey();
salesOrderKey.Id = "INVCUSTOMER";
try
{
// Retrieve the sales order
salesInvoice = wsDynamicsGP.GetSalesInvoiceByKey(salesOrderKey, context);
int dd = salesInvoice.Lines[3].Key.LineSequenceNumber;
//int dd1 = salesInvoice.Lines[0].Serials[0].Key.SequenceNumber ;
//int dd2 = salesInvoice.Lines[0].Serials[0].Key.SalesLineKey.LineSequenceNumber;
// Create the line ItemKey
//salesInvoice.Lines[4].DeleteOnUpdate = true;
ItemKey itemKey = new ItemKey();
itemKey.Id = "TICKETNEW";
// Create the line for removal
salesInvoiceLine = new SalesInvoiceLine();
salesInvoiceLine.Key = new SalesLineKey();
salesInvoiceLine.Key.LineSequenceNumber = 65535;
salesInvoiceLine.Key.SalesDocumentKey = salesOrderKey;
salesInvoiceLine.DeleteOnUpdate = true;
salesInvoiceLine.ItemKey = itemKey;
//salesInvoiceLine.CommentKey =
// Create an array of sales order lines
// Initialize the array with the sales order line object
SalesInvoiceLine[] lineToRemove = { salesInvoiceLine };
// SalesInvoiceLine[] lineToRemove = { salesInvoice.Lines[3] };
// Add the sales order line array to the sales line object
salesInvoice.Lines = lineToRemove;
// Retrieve the update policy for sales orders
salesOrderUpdatePolicy = wsDynamicsGP.GetPolicyByOperation("UpdateSalesInvoice", context);
// Update the sales order object
wsDynamicsGP.UpdateSalesInvoice(salesInvoice, context, salesOrderUpdatePolicy);
//statusLabel.Text = "Line removed successfully!";
}
catch (Exception ex)
{
//statusLabel.Text = se.Message + se.StackTrace;
}
Thanks.
*This post is locked for comments