Setting up a Field Style based on the callers group or role.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 12:38 PM
Hi, I am trying to create a field style that indicates to help desk that a user is part of a particular group or role.
Similar to the VIP. But that doesn't highlight the names, and doesn't require a true/false toggle in case we need to add other indicators for different groups of users.
I've tried different approaches, but not having a lot of luck.
Last thing I tried.
Solved: Incident field style for Roled user - ServiceNow Community
Running a Tokyo Instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 12:53 PM - edited 04-20-2023 12:54 PM
@Andrew Balleto Try this
To achieve the desired functionality of indicating that a user is part of a particular group or role, you can use a UI policy and a client script. Here are the steps to follow:
- Create a new UI policy for the table containing the field you want to style. For example, if you want to style the Caller field in the Incident table, create a new UI policy for the Incident table.
- In the UI policy, add a new "onLoad" client script action.
- In the client script, use a GlideAjax call to retrieve the current user's groups and roles.
Here is an example of what the client script might look like:
function onLoad() { var ajax = new GlideAjax('GetUserGroupsRoles'); ajax.addParam('sysparm_name', 'getUserGroupsRoles'); ajax.getXML(updateFieldStyle); } function updateFieldStyle(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); var fieldStyle = ''; if (answer.indexOf('IT Support') !== -1) { // Add style for IT Support members fieldStyle = 'background-color: #FFFF00; color: #000000;'; } var callerField = g_form.getControl('caller'); callerField.style = fieldStyle; }
In this example, the client script calls a GlideAjax script named "GetUserGroupsRoles" and retrieves the current user's groups and roles. It then checks if the user is a member of the "IT Support" group and sets the fieldStyle variable to highlight the Caller field if the user is a member.
- Create a new Script Include called "GetUserGroupsRoles".
- In the new Script Include, add a new function called "getUserGroupsRoles" that retrieves the current user's groups and roles.
Here is an example of what the Script Include might look like:
var GetUserGroupsRoles = Class.create(); GetUserGroupsRoles.prototype = Object.extendsObject(AbstractAjaxProcessor, { getUserGroupsRoles: function() { var groups = gs.getUser().getMyGroups(); var roles = gs.getUser().getRoles(); var result = groups.join(', ') + ', ' + roles.join(', '); return result; }, type: 'GetUserGroupsRoles' });
In this example, the Script Include uses the "getMyGroups()" and "getRoles()" methods to retrieve the current user's groups and roles. It then concatenates the groups and roles into a string and returns the string as the result.
- Save the UI policy, client script, and Script Include.
Now, when a user who is a member of the "IT Support" group is selected as the Caller, the Caller field will be highlighted with the style you defined. You can add additional if statements to the client script to highlight the field for other groups or roles as needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 07:24 AM
Sorry, I feel like I am missing something.
If I try to add the first code to the Field Style it does not like it, because its an onLoad command instead of a onCondition.