Skip to Content

Service Layer: How to update, add and remove items for sales order

I’m currently using the service layer to test creating a sales order. Below is what I archive so far.

The next thing I’m trying to do is update item A00001, remove A00002 and add A00003. I know this can be done with the patch method and applying B1S-ReplaceCollectionsOnPatch equals to true to the header. Below is the header info set in Postman.

Below is the PATCH request I’m trying to make to update line number 0 and add item code A00003. However, I get an error as shown below. Would you know why this call didn’t work?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Jul 11, 2017 at 05:47 PM

    I found up why things didn't work. For LineNum 0 that I wanted to update, Service Layer wanted to know the item number. After I included the item number for LineNum 0, it did update this line with the new value, removed my second item A00002 and added a new item A00003. It woudl have been nice it would have been able to update LineNum 0 without referencing the item code.

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 10, 2017 at 03:30 PM

    The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request- URI. It's definition is righ here

    So, whenever you try to make a PATCH, by definition, service layer will try to update the fields that are on your request. If a certain line is not there, it won't be deleted, but ignored.

    To achieve what you want, use the PUT method. It will require the whole content of the Order object in the body, but will replace completely what you define on the DocumentLines array.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 03, 2017 at 01:48 PM

    Hi, I have the exact same requirement as explained here on SAP Business One v 9.2.

    I tried using PUT method as well as PATCH method with 'B1S-ReplaceCollectionsOnPatch = true'. For both the scenarios I got the exact same error as shown below:

    Fields LineNum, ItemCode, UoMCode, UoMEntry are all mentioned in the payload for every document line.

    Could you please help.

    Add comment
    10|10000 characters needed characters exceeded