Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Often we're asked about having the ability to update user's authorizations using the DI API. In the following blog I'd like to summarize the DI objects that are currently exposed and can be used for this purpose (for version 2007).

 

Let's distinguish between User permissions and System Permissions.

 

•1)    User Permissions

You can add and update User Permissions using the DI API. The equivalent form in SAP Business One GUI is:

Administration -> System initialization -> Authorizations -> Additional Authorization.

For creating and updating user authorizations, use the UserPermissionTree DI object.

UserPermissionTree is a business object that represents the User Authorization Form. This object enables to manage user authorization for new forms.

 

First step: Define permissions to my form. In order to do it I've used the code below:

SAPbobsCOM.UserPermissionTree oUPT =

(SAPbobsCOM.UserPermissionTree)oComp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserPermissionTree);

   oUPT.PermissionID = "MyPermission1";

   oUPT.Name = "MyPerm1";

oUPT.Options = SAPbobsCOM.BoUPTOptions.bou_FullReadNone;

oUPT.Add();

 

Second step: Grant user permission to my form. In order to do it I've used the code below:

SAPbobsCOM.Users oUsers =

(SAPbobsCOM.Users)oComp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUsers);

   oUsers.GetByKey(29);

   oUsers.UserPermission.PermissionID = "MyPermission1";

   oUsers.UserPermission.Permission =

SAPbobsCOM.BoPermission.boper_Full;

oUsers.Update();

 

** For more information, please refer to the UserPermissionTree page in the SAP Business One SDK Help Center.

 

  • 2) System Permissions

 

You can modify system permissions using the DI API.

The equivalent in SAP Business One GUI is:

Administration -> System initialization -> Authorizations -> General Authorization

 

For updating system permissions, use the following DI object method:

SBObob -> SetSystemPermission.

 

Public Sub SetSystemPermission( _

   ByVal UserName As String, _

   ByVal PermissionID As String, _

   ByVal Permission As Long _

)

 

UserName = A User Code

PermissionId = Take the relevant string from the permission Id list in the help center. (For example: Business Partner = 38)

Permission = Choose the permission level you want to grant. (For example: 1= Full authorization)

 

For example:

One of the users (for example: "User1") needs to have full authorization to work with "Business Partner" object.

In order to do it I need to use the SetSystemPermission method of the DI SBObob object, as shown below:

 

SAPbobsCOM.SBObob bobi =

(SAPbobsCOM.SBObob)oComp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);

bobi.SetSystemPermission("User1", "38", 1);

 

** For more information, please refer to the SetSystemPermission page in the SAP Business One SDK Help Center.

1 Comment