Imagine in your customization you have a requirement, to check what is the current role of the user who is logged in? Maybe only someone with admin role should click on your button.
Before we get to the example, you should search online help for “API to access to user profile”
Now here is the example, I am going to add a new button in my Sales order that checks for Admin profile.
- Open Development, Script Dictionary , Windows.
- Select OSOH window.
- Click on Buttons/Menus tab and add a new button like below.
- Click Save and Validate.
- Open Setup, Sales, Entry Transactions, Orders.
- Validate your entry transaction.
- Open Development, Script Dictionary, Script Editor and add below code.
$ACTION
Case ACTION
When "EXEBOUT" : Gosub BOUTON
Endcase
Return##############
$BOUTON
If BOUT="7" ###### this is the code of our button in Window dictionary
### A function that returns the current role codeLocal Clbfile RESHEAD
Local Clbfile RESBODYLocal Integer STATUSCODE
### Module, function and element to be returned
Local Char MODULE(100) : MODULE = 'syracuse-4gl-api/lib/collaboration'
Local Char FONCTION(30) : FONCTION = 'getUserProfile'
Local Char RETURNS(50) : RETURNS = "selectedRole.code"### The function is asynchronous
Local Char MODE(4) : MODE = 'wait'### The callback argument is located in the first place for this function
Local Integer CALLB : CALLB=0### No Base 64 in or out coding, the arguments can remain empty
Local Char B64_IN(20), B64_OUT(20)### No additional arguments
Local Clbfile ARGUMENTS : ARGUMENTS = ""# Let's call the function
STATUSCODE = func ASYRWEBSER.EXEC_JS(MODULE, FONCTION, MODE, ARGUMENTS, B64_IN, CALLB, RETURNS, B64_OUT, RESHEAD, RESBODY)# If the call fails, return an empty code
If STATUSCODE<>200 : infbox("Something went wrong") : Endif
If STATUSCODE=200 and RESBODY="ADMIN" : infbox("Current Role is " -RESBODY- " and it's Ok for you, to click on this link") : Endif
If STATUSCODE=200 and RESBODY<>"ADMIN" : infbox("Current Role is " -RESBODY- " Sorry only admin can click on this link") : Endif
Endif
Return - Save and Compile.
- Open Sales, Orders, Orders.
- Click on "What is my Role" button.
- You will see below.
Conclusion :You can use this API to check for current user Role.