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

That line of code is only checking if the user has the role. You also need to add some code that will be executed depending on the result of the role check. What does your complete script look like?

Hi,

I have tried with this code, but still it's not working. Can you suggest me in what way I can modify the code?

 

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
}
}

With hasRole() method, you can only check for a single role. So you either need to call it twice:

var isAdmin = g_user.hasRole('itil_admin') || g_user.hasRole('admin');

 or use hasRoleFromList() method instead, which accepts multiple roles:

var isAdmin = g_user.hasRoleFromList('itil_admin','admin');

 

Hi Vipul Gupta,

You mentioned in the script the "admin" role, which may be working for you, but my need is the "itil_admin" role.