- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 06:55 AM
Hi All
I need to create Client Script to check if logged in user is in group which name starts with 'AB'. If yes then remove two options from Urgency field in Incident form: 1- High and 2 - Medium
How can I create the script?
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 07:04 AM
You can use combination of display business rule + onload client script
Business rule:
(function executeRule(current, previous /*null when async*/ ) {
// Query the sys_user_grmember table to get the groups of the logged-in user
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', gs.getUserID());
gr.addQuery('group.name', 'STARTSWITH', 'AB');
gr.setLimit(1);
gr.query();
g_scratchpad.userGroups = gr.hasNext().toString();
})(current, previous);
onLoad client script:
function onLoad() {
var isMember = g_scratchpad.userGroups;
// If the user is in an 'AB' group, remove 'High' and 'Medium' options from the Urgency field
if (isMember.toString() == 'true') {
g_form.removeOption('urgency', '1'); // High
g_form.removeOption('urgency', '2'); // Medium
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 06:59 AM
Hi @Kasia5
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 07:04 AM
You can use combination of display business rule + onload client script
Business rule:
(function executeRule(current, previous /*null when async*/ ) {
// Query the sys_user_grmember table to get the groups of the logged-in user
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', gs.getUserID());
gr.addQuery('group.name', 'STARTSWITH', 'AB');
gr.setLimit(1);
gr.query();
g_scratchpad.userGroups = gr.hasNext().toString();
})(current, previous);
onLoad client script:
function onLoad() {
var isMember = g_scratchpad.userGroups;
// If the user is in an 'AB' group, remove 'High' and 'Medium' options from the Urgency field
if (isMember.toString() == 'true') {
g_form.removeOption('urgency', '1'); // High
g_form.removeOption('urgency', '2'); // Medium
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 05:11 AM
Thank you!