web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Using GP Web Service: How do I delete a SalesOrderLine from a SalesOrder?

(0) ShareShare
ReportReport
Posted on by

Can someone help me delete a SalesOrderLine from a SalesOrder?

I'm using the GP WS Native Endpoint

My code executes without an error.

The bold line of code below is where I'm creating a new array without the line I want deleted.  This code executes and newLines has the Lines without the one I want deleted.

However, after updating the SalesOrder, the line I removed still remains.

var salesDocumentKeyObject = new SalesDocumentKey {Id = salesDocumentKey, CompanyKey = this.CompanyKey};

var salesOrder = this.DynamicsGpClient.GetSalesOrderByKey(salesDocumentKeyObject, this.Context);

var newLines = salesOrder.Lines.Where(l => l.Key.LineSequenceNumber != lineItemSequence).ToArray();

salesOrder.Lines = newLines;

var salesOrderUpdatePolicy = this.DynamicsGpClient.GetPolicyByOperation("UpdateSalesOrder", this.Context);

this.DynamicsGpClient.UpdateSalesOrder(salesOrder, this.Context, salesOrderUpdatePolicy);

Thank you for any help,

Karl

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: Using GP Web Service: How do I delete a SalesOrderLine from a SalesOrder?

    I don't think the update method will trigger a delete for things that don't exists. Instead try using the DeleteSalesOrder method.

    msdn.microsoft.com/.../cc508447.aspx

  • Community Member Profile Picture
    on at
    RE: Using GP Web Service: How do I delete a SalesOrderLine from a SalesOrder?

    I misread you're attempted delete the SalesOrderLine. Nonetheless, if you cannot reach a solution you could delete the whole SalesOrder and create new.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Using GP Web Service: How do I delete a SalesOrderLine from a SalesOrder?

    Microsoft Dynamics GP Web Service has poor documentation and examples.  Deleting a sales order line is a common scenario, but ZERO guidance is provided.

    Do delete a sales order line, you retrieve the order, locate the line to delete and set the sales order line property, DeleteOnUpdate to true, and then save the order.

    Updated code below:

       var salesDocumentKeyObject = new SalesDocumentKey {Id = salesDocumentKey, CompanyKey = this.CompanyKey};

       var salesOrder =    this.DynamicsGpClient.GetSalesOrderByKey(salesDocumentKeyObject, this.Context);

       var target= salesOrder.Lines.FirstOrDefault(l => l.Key.LineSequenceNumber == lineItemSequence);

       if (target != null) {

       target.DeleteOnUpdate = true;

       }

       var salesOrderUpdatePolicy = this.DynamicsGpClient.GetPolicyByOperation("UpdateSalesOrder", this.Context);

       this.DynamicsGpClient.UpdateSalesOrder(salesOrder, this.Context, salesOrderUpdatePolicy);

  • Community Member Profile Picture
    on at
    RE: Using GP Web Service: How do I delete a SalesOrderLine from a SalesOrder?

    Thank you for the reply.  Finally after hours, found the solution.  See my reply.

    Have a great day,

    Karl

  • Community Member Profile Picture
    on at
    RE: Using GP Web Service: How do I delete a SalesOrderLine from a SalesOrder?

    Again, thank you for your reply.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans