Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Delete duplicate line

(0) ShareShare
ReportReport
Posted on by 285

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

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics

Product updates

Dynamics 365 release plans