cancel
Showing results for 
Search instead for 
Did you mean: 

User Authorization on Customize Forms(User Forms)

Former Member
0 Kudos

Hi Experts,

I want to implement authorization on Customize forms by code... i am using .NET Framework with C# for development.... please guides me...

thanks

deepak

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Dear Deepak Gaur,

Here the sample code from SDK help:



Adding a PermissionTree - parent object (Visual Basic) 
[Visual Basic]

Dim RetVal As Long
Dim ErrCode As Long
Dim ErrMsg As String
Dim mUserPermission As SAPbobsCOM.UserPermissionTree
Set mUserPermission = oCompany.GetBusinessObject(oUserPermissionTree)

'//Mandatory field, which is the key of the object.
'//The partner namespace must be included as a prefix followed by _
mUserPermission.PermissionId = "SM_MathClass"

'//The Name value that will be displayed in the General Authorization Tree
mUserPermission.Name = "SM_MathClass"

'//The permission that this object can get
mUserPermission.Options = bou_FullReadNone

'//In case the level is one, there Is no need to set the FatherID parameter.
mUserPermission.Levels = 1
RetVal = UserPermission.Add
oCompany.GetLastError RetVal, ErrMsg
'//In case this permission object has a son permission object
 
 

Adding a PermissionTree - child object (Visual Basic) 
[Visual Basic]

Dim RetVal As Long
Dim ErrCode As Long
Dim ErrMsg As String
Dim mUserPermission As SAPbobsCOM.UserPermissionTree
Set mUserPermission = oCompany.GetBusinessObject(oUserPermissionTree)

mUserPermission.PermissionId = "SM_MathClassSon"
mUserPermission.Name = "SM_MathClassExam"
mUserPermission.Options = bou_FullNone

'//For level 2 and up you must set the object's father unique ID
mUserPermission.Levels = 2
mUserPermission.FatherID = "SM_MathClass"
'//this object manages forms
mUserPermission.UserPermissionForm.FormType = "GL_MathClass"

RetVal = mUserPermission.Add
oCompany.GetLastError RetVal, ErrMsg


[Visual Basic]

Dim RetVal As Long
Dim ErrCode As Long
Dim ErrMsg As String
Dim mUser As SAPbobsCOM.Users

Set mUser = oCompany.GetBusinessObject(oUsers)

'//The user unique ID is 2
RetVal = mUser.GetByKey(2)

'//Setting a new sub object for the User that hold the user permission for the user permission object
mUser.UserPermission.PermissionId = "SM_MathClassSon"

'//Seting full permission for User 2 to manage SM_MathClassSon sub object
mUsers.UserPermission.Permission = boper_Full

RetVal = mUsers.Update
oCompany.GetLastError RetVal, ErrMsg 
 

Setting user permission (Visual Basic) Copy Code 
Dim RetVal As Long
Dim ErrCode As Long
Dim ErrMsg As String
Dim mUser As SAPbobsCOM.Users

Set mUser = oCompany.GetBusinessObject(oUsers)

'//The user unique ID is 2
RetVal = mUser.GetByKey(2)

'//Setting a new sub object for the User that hold the user permission for the user permission object
mUser.UserPermission.PermissionId = "SM_MathClassSon"

'//Seting full permission for User 2 to manage SM_MathClassSon sub object
mUsers.UserPermission.Permission = boper_Full

RetVal = mUsers.Update
oCompany.GetLastError RetVal, ErrMsg

Best Regards

Jane Jing

SAP Business One Forums team

Former Member
0 Kudos

Dear Sir,

This code snippet is available in SDK Help,. It contains this line

mUserPermission.Levels = 1

and this line shows error that it's readonly property

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Deepak,

You can use the UserPermissionTree object to manage the user authorization tree, (in application, it corresponds to Select Administration --> System Initialization --> Authorization --> User Authorization Form), and then use UserPermission object to manage the users' permissions.

Best regards,

Lin