Check if user is member of servicenow group in client script

scocuzza
Kilo Contributor

I need to remove certain options from a dropdown field based on whether the current user is a member of a "Database application support" group that we have in our service now instance, but i cannot use the following

if (gs.getUser().isMemberOf('Database Application Support')) {

}else{

}

The object "gs" should not be used in client scripts.

 

How can I check if the user is a member of this group?

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Since gs is server side script, you can't use it in client script.

 

There are two options.

 

1st one is to create a client callable script include and call the script from client script using glideajax.

 

The other option is create a new role and assign to Database Application Support.

Then in client script you can check if (g_user.hasRoleExactly('your_new_role'))


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

3 REPLIES 3

SanjivMeher
Kilo Patron
Kilo Patron

Since gs is server side script, you can't use it in client script.

 

There are two options.

 

1st one is to create a client callable script include and call the script from client script using glideajax.

 

The other option is create a new role and assign to Database Application Support.

Then in client script you can check if (g_user.hasRoleExactly('your_new_role'))


Please mark this response as correct or helpful if it assisted you with your question.

Thanks creating and checking for the new role from a client script works

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi,

 

You have to run this at the server side. You can do the glideajax and pass the parameters to get the output. The other option is to create a display business rule and store the output in scratchpad and then validate it at the client side.

GlideAjax approach:  https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/reference/r_GlideAjax.html

Scratchpad approach: https://docs.servicenow.com/bundle/london-application-development/page/script/business-rules/concept/c_ScriptingWithDisplayBusinessRules.html

 

-Pradeep Sharma