bgmulinari / B1SLayer

A lightweight SAP Business One Service Layer client for .NET
MIT License
124 stars 42 forks source link

How to PATCH TaxCodes on Orders? #22

Closed mooncat22 closed 1 year ago

mooncat22 commented 1 year ago

Hi! I trying to figure out how to update TaxCodes on an order. The TaxCode is on each Document Line. How would I PATCH each Line item?

I understand updating top level: var updateOrderComments= new { Comments = "Update my Comments" };
await serviceLayer.Request("Orders", 191).PatchAsync(updateOrderComments);

But can't get the right syntax to update the Document Lines array.

From the B1 Service Reference: { "CardCode": "c001", "DocDueDate": "2014-04-04", "DocumentLines": [ { "ItemCode": "i001", "Quantity": "100", "TaxCode": "T1", "UnitPrice": "30" } ] }

bgmulinari commented 1 year ago

Hi, @mooncat22. You should use something like a List or an Array within your object to represent each document line.

That can get a bit convoluted with an anonymous object, so you might want to create classes to represent your document and its lines. Something like this:

public class Document
{
    public string DocNum { get; set; }
    public string CardCode { get; set; }
    ...
    public List<DocumentLine> DocumentLines { get; set; }
    ...
}
public class DocumentLine
{
    public string ItemCode { get; set; }
    public decimal Quantity { get; set; }
    ...
}

So in your PATCH request you pass your Document type object containing all properties and document lines you wish to update.

mooncat22 commented 1 year ago

Thank you, this works great!

bgmulinari commented 1 year ago

You're welcome. I'll be closing the issue since your doubt seems to be cleared, but if you still need help, please let me know.