Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to check user group "Role" in UI Policy

subashds6515
Tera Contributor

By using UI policy , i'm going to find  the user 'group role . if the group role  is itil_admin , will make the field editable for the particular user.

23 REPLIES 23

Hi Vipul Gupta,

I did exactly what you mentioned early, but it's not working for me.

subashds6515_0-1683472374354.png

 

subashds6515_1-1683472418002.png

 

subashds6515_2-1683472445444.png

 

probably because there is a UI policy that comes OOB which is contradicting to this.

 

same error.JPG

GlideSystem (gs) is a server-side API. You cannot use it in a UI Policy because UI Policy scripts are client-side. Use the client-side GlideUser API instead:

g_user.hasRole('admin')

 

its not working. changed the script to g_user.hasrole('itil_admin').

Hi Vipul Gupta,

I have sheared my UI policy code for reference; please look at it. This code is not working for me.

 

function onCondition() {
var isAdmin = g_user.hasRole('itil_admin' || 'admin');
if (isAdmin) {
g_form.setReadOnly('short_description', false); // Title
g_form.setReadOnly('caller_id', false); // Client Name
g_form.setReadOnly('contact_type', false); // Channel
g_form.setReadOnly('category', false); // Category
g_form.setReadOnly('subcategory', false); // Subcategory
g_form.setReadOnly('cmdb_ci', false); // Configuration Item
g_form.setReadOnly('u_support_team', false); // Support team
g_form.setReadOnly('assignment_group', false); // Assignment Group
g_form.setReadOnly('assigned_to', false); // Assigned to
g_form.setReadOnly('activity_due', false); // Activity due
g_form.setReadOnly('close_code', false); // Close Code
}
}