cancel
Showing results for 
Search instead for 
Did you mean: 

Uncheck -- Assigned Branches in Users Table via Service Layer

rahuljain257
Participant
0 Kudos

Hi Support team,

I need your help with something. I want to uncheck the User Branch Assignment option in SAP B1, but I don't know how to do it. Can you please guide me through the steps?

Sample Screenshot of Branch for UserSign 71 -

Scenario 1st - In the above screenshot, you can see that Branch No - 8 (ABC), No - 9 (NOIDA1), No - 10 (NOIDA2) are not assigned to the UserSign 71. But when I try to assign them using the method below, it works fine.

Patch Request -

Sample Screenshot of Branch for UserSign 71 -

Scenario 2 - My next request is to uncheck / deselect / remove all the branches that are assigned to this user, but this doesn't work. Why is that ??

1st Way - It didn't worked

2nd Way - It didn't worked tooo.

Regards,

Rahul jain

Accepted Solutions (1)

Accepted Solutions (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

Hi rahuljain2570,

Updated reply:

Service Layer supports removing an element in the collection property by adding a special header in the request: B1S-ReplaceCollectionsOnPatch=true.

HTTP Header: B1S-ReplaceCollectionsOnPatch=true sets the update method as REPLACE, which means the whole content will be replaced and the mismatched old rows will be deleted.

In other words, it is to update the matched lines and delete the unmatched lines.

Therefore, use the mentioned HTTP Header in the request while trying to remove/unassign the data from UserBranchAssignment[] collection.

Hope it helps!

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

Answers (1)

Answers (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

Hi rahuljain2570,

Using DI API, it will be done as below:

SAPbobsCOM.Users oUser = (SAPbobsCOM.Users)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUsers);
if (oUser.GetByKey(1))
{
    oUser.UserBranchAssignment.SetCurrentLine(1);
    var ID = oUser.UserBranchAssignment.BPLID;
    oUser.UserBranchAssignment.Delete();
    int UUSR = oUser.Update();

    if (UUSR != 0)
    {
        MessageBox.Show(oCompany.GetLastErrorDescription());
    }
}

Therefore, I doubt that PATCH is going to work for you. I think that you should go for PUT.

I am yet to test it using Service Layer. I will confirm and update this reply.

Kind regards,

ANKIT CHAUHAN

SAP Business One Support