Preventing users from logging a P1 incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 05:43 AM
Good afternoon all 🙂
I created a client script that prevents users from logging a P1 incident. When they do, they get a message saying they should contact the ServiceDesk. The incident gets saved as low priority. I would like people in a certain group (BST-ServiceDesk) to be able to change the priority to P1 if needed. Please help with my code. I get the message part right, but the part where only BST-ServiceDesk can upgrade it to P1 still gives an error.
I made the area where I think the problem is red and the error I am getting is: Error MessageonSubmit script error: TypeError: Cannot read properties of undefined (reading 'indexOf'):
function () { [native code] }
function onSubmit() {
// Get the priority field value
var priorityField = g_form.getValue('priority');
// Check if the priority is set to P1
if (priorityField === '1') {
// Check if the user is part of the 'BST-Service Desk' group
var userGroups = g_user.userGroups;
if (userGroups.indexOf('BST-Service Desk') !== -1) {
// Allow the ServiceDesk to change the priority to P1
return;
} else {
// Display an error message
g_form.addErrorMessage('P1 incidents are not allowed to be logged. Please contact the ServiceDesk for assistance.');
// Set impact and urgency to 2 (Medium)
g_form.setValue('impact', '2'); // Set impact to Medium
g_form.setValue('urgency', '2'); // Set urgency to Medium
// Save the form
g_form.submit();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 06:01 AM
Hi @Thereza Van der ,
You can create business rule as below. If user tries to create or update incident priority to P1 then it will change impact and urgency to 3 automatically and will give message on the screen. Only Service desk can change the priority to P1.
Script:
You can create system property to store the sys_id of "BST-Service Desk" group and then use in above script using "gs.getProperty()" method as best practice.
Thanks and Regards,
Chiranjeevi R
Please mark as Correct Answer/Helpful, if applicable.
Chiranjeevi
ServiceNow Developer | | ITSM | | ServiceNow Discovery | | Event Management | | Service Mapping | | CMDB
Please mark as Correct Answer/Helpful, if applicable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 06:29 AM
Don't make it complicated, follow either of one solution.
1) Hide P1 values from fields and make it visible only for set of groups/users.
2) Use before BR and abort insert in case if it is not done by correct set of users/groups.
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 09:27 AM - edited 09-11-2024 09:31 AM
Couple things:
- is this in a Catalog Item/Record Producer or the native form view? If native view, why are non helpdesk users allowed to do that?
- you could add a message to the screen when the user changes the Priority to 1 instead of allowing them to submit it
- using Business Rules in these use cases are not very useful: why allow a user to "submit" something, throw an error then bring them back? Not a nice experience.
- "g_user.userGroups" does not exist. Take a look at this ServiceNow Guru article: User Object Cheat Sheet
- does that Group have a unique Role that could be leveraged instead?