bgmulinari / B1SLayer

A lightweight SAP Business One Service Layer client for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Document Lines Patching content error/structure

enshadowed opened this issue · comments

commented

First of all, thank you for the work you have done on B1SLayer. It is indeed very helpful. I have gone through your documentation both on sap forums and also here but I haven't been able to see how to handle lines or if it is even doable using B1SLayer so excuse my ignorance and for opening this as an issue.

Assuming the following scenario;

Update Production Order 3114, set warehouse to '163' for line number '2' and line number '3'.

conventionally it would be a PATCH call to /ProductionOrders(3114) with content of

var content = new StringContent("{\"ProductionOrderLines\": [{\"LineNumber\":2,\"Warehouse\":\"163\"},{\"LineNumber\":3,\"Warehouse\":\"163\"}]}", null, "text/plain");

Using

await serviceLayer.Request("ProductionOrders", "3114").PatchAsync(updatedPWInfo); returns Property LineNumber of ProductionOrder is invalid. which is true, its a property of ProductionOrderLines which is under ProductionOrders

await serviceLayer.Request("ProductionOrderLines", "3114").PatchAsync(updatedPWInfo); returns Unrecognized Resource Path which is normal and doesn't exist on the API.

I believe the issue is in updatedPWInfo what would the structure be for it to work with the list of lines just like in the productionOrder scenario above?

Hi, @enshadowed. I was able to update the the warehouse without issues with the examples bellow:

// here I'm using an anonymous type object, but you can use a declared class, if you wish
var orderInfo = new
{
    ProductionOrderLines = new[]
    {
        new
        {
            LineNumber = 2,
            Warehouse = "02"
        },
        new
        {
            LineNumber = 3,
            Warehouse = "02"
        }
    }
};

await serviceLayer.Request("ProductionOrders", 38).PatchAsync(orderInfo);

If you want to send the JSON body as a string, this would also work:

string orderInfoString = "{\"ProductionOrderLines\":[{\"LineNumber\": 1,\"Warehouse\":\"02\"},{\"LineNumber\":2,\"Warehouse\":\"02\"}]}";
await serviceLayer.Request("ProductionOrders", 38).PatchStringAsync(orderInfoString);

Let me know if this helps you.

commented

Hey, thanks for the prompt reply, the mistake was indeed as I suspected. I wasn't populating the new before each line along with missing the new[] i had it at the beginning only.

Thank you again for your response and the stellar work on this project.

No problem. I'm closing the issue, but if you still need help, let me know.