cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove a StockTransferLine from a StockTransferRequest using oData and Service Layer

robpankhurst
Discoverer
0 Kudos

We’re writing an application that will allow us to use oData and the HANA Service Layer to perform CRUD operations on Stock Transfer Requests. Thus far we have been able to Add and Amend individual Stock Transfer Requests and Lines. However, Remove doesn't have any affect on StockTransferLines, i.e., if I "Remove" a specific line within the StockTransferLines collection within the StockTransferRequest, this is ignored and the line is retained when the StockTransferRequest is updated.

I've included a code snippet below that comments the bits that work / don't work:

HanaConnectionhanaConnection =newHanaConnection(connString.ConnectionString);

hanaConnection.Open();

SAPServiceLayer.SAPB1.StockTransferstockTransferRequestUpdate =newSAPServiceLayer.SAPB1.StockTransfer();

stockTransferRequestUpdate = currentOdataService.GetStockTransferRequest(1044);

if(null!= stockTransferRequestUpdate)

{

// Add Line - WORKS with no issue

StockTransferLinestl_11 =newStockTransferLine();

stl_11.ItemCode ="10";

stl_11.Quantity = 1;

stl_11.UnitPrice = 2;

stl_11.FromWarehouseCode ="MAIN";

stl_11.WarehouseCode ="002";

stockTransferRequestUpdate.StockTransferLines.Add(stl_11);

StockTransferLine stl = stockTransferRequestUpdate.StockTransferLines.Where(tl => tl.LineNum == 1).Single();

// Amending Existing line works

stl.Quantity = 10;

stl.ItemCode = "100";

// Remove Line - Doesn't work, and doesn't throw any error that I can see

stockTransferRequestUpdate.StockTransferLines.Remove(stl);

// Or

stockTransferRequestUpdate.StockTransferLines.RemoveAt(1);

// Update the StockTransferRequest with either Add / Amend / Remove options above

boolupdateSTR = currentOdataService.UpdateStockTransferRequest(stockTransferRequestUpdate);

}

I’m connecting as B1ADMIN user with full rights to CRUD on the Database.

Given that Adding a line; and amending existing lines works without issue. I'm thinking that either I've missed something blindingly obvious or maybe the Remove method requires additional permissions to be explicitly allowed somewhere else other than on the User or maybe the Remove method is dependent on other operations/amendments.

Can anyone help point me in the right direction, please?

Thanks & regards,

Rob

Accepted Solutions (0)

Answers (4)

Answers (4)

robpankhurst
Discoverer
0 Kudos

Hi Ralph,

Just for information. A colleague has just pointed me towards this Note which looks very similar to the issue that I'm experiencing although I don't seem to get the error message and I'm updating something other than Orders.

https://launchpad.support.sap.com/#/notes/2850921

I'll still look at REST as long-term it looks a better way to go.

Regards,

Rob

former_member197733
Contributor
0 Kudos

This is for $batch requests. Not exactly your case.

As said before, make sure to set the B1S-ReplaceCollectionsOnPatch:true header, if using PATCH.

robpankhurst
Discoverer
0 Kudos

Hi Ralph,

Yes, you're correct I am using oData via WCF, which I'm currently more comfortable with than REST at the moment. So as you say there probably is a bug with the WCF implementation. Looks like I'll have to bring forward my self-training in REST. I'll take a look at your dirty sample to see if I can get something to work using this instead.

Thanks & regards,

Rob

robpankhurst
Discoverer
0 Kudos

Hi Ralph,

Thanks for the reply.

However, what you describe is basically what I'm doing, although I'm using the oData .Remove() method to try to delete a particular line in the request. This doesn't work, although the .Add() method does.

For your first point I am indeed using the InventoryTransferRequest entity. This uses a StockTransfer object to build the InventoryTransferRequest.

I'm afraid that I don't think this takes me any further forward without completely changing the method I'm using to try to achieve this.

If the .Remove() method doesn't work while the .Add() method does - is this a bug?

Regards,

Rob


former_member197733
Contributor
0 Kudos

No,

I showed before that such operations could be performed via the REST client (postman). Therefore, there aren't any bugs in Service Layer related to this matter.

.add(), .Remove() and other methods in your code are not part of Service Layer but implementations of the framework you are using (is that WCF??). They seem to only work on the data structure, not on the HTTP request. So if there is a bug, is on the framework..

What is the update() doing? A PATCH or a PUT? If the first, have you set the required headers explained in the mentioned blog?

I can't advise on frameworks, but have you tried using pure .NET? I have a dirty sample which I did years ago.

Postman also generates C# code using RestSharp, it might be another option.

former_member197733
Contributor
0 Kudos

Hi there, Rob.

Deletion of Entity lines is described in this blog. Basically you need do perform a GET the object followed by a PUT/PATCH operation with the whole lines array that you want to keep.

Close/Cancel action are described in the Sevice Layer API reference: on your HANA server @ https://<HanaHost>:50000 or in this site (as a courtesy, this is no official doc)

There is also an explanation in the guide "Working with SAP Business One Service Layer in the section "Actions"

A closer look to your case, shouldn't you use the InventoryTransferRequests entity instead of StockTransfer?

https://i.imgur.com/clxq4Eb.png

I see that StockTransfers do not allow lines removal on the B1 Client

InventoryTransferRequests It works fine from the REST client see below the details.

https://imgur.com/a/VM3a6rp