How can i check user’s role in javascript? There is any function?
Subject: Role in javascript
Hi Bobb,
There is no function in JS to check the user’s role.
You must to create it.
To start, there is one way :
HTML passtrhu on form, page,…
Declare JS variable to get user roles
Formula for (or can be Computed for display field):
@Implode(@userRoles;“,”)
In JS header of form,…
“UserRole” is a parameter to pass in function
function checkUserRole(UserRole) {
//Create an array : comma (,) is the separator (look Fomula above)
var UserRolesArray = UserRole.split(‘,’)
//Loop through the array
for (i=0,i<UserRolesArray.length,i++)
{
alert('You have the role '+UserRolesArray[i])
};
};
Use of JS function
e.g. put this in Button (JS code) :
variable “CurrentUserRole” passed in function
checkUserRole(CurrentUserRole)
Voilà !
HTH
Thierry
Subject: RE: Role in javascript
Where can I put code: ?
I have this on form. When I click Button, which has: checkUserRole(CurrentUserRole), I begin message:“There isn’t CurrentUserRole”. Why?
Subject: RE: Role in javascript
The message appears because the JS variable is not found.
Put the code on your form (e.g. at the top) like HTML passthru (select it and
go to menu “Text” > click on “HTML passthru”) (or you can put the code between
square brackets e.g. script…].
DON’T hide the lignes (text properties > fourth tab).
must be between apostrophes (‘’).
In browser, when your form is loaded, with “view source code” check if the code
appears, if so, you will see :
var CurrentUserRole = ‘[$$WebClient], [Role], etc’
Thierry
Subject: RE: Role in javascript
Assuming you can use a form, just put a hidden, multi-value, CFD field on the form containing @userroles. Set the form’s “Generate html for all fields” property, and through javascript you’ve got a semicolon-delimited string you can split into an array of roles.