- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 10:50 PM
Wrote a client script and Display BR on Task table but not working
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 02:18 AM
@VijayKummamuru - You can use onCellEdit client script that runs on the list view of the table to control with same logic.
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 02:21 AM
you can use list_edit ACLs on those 2 fields to block the field from getting updated in list
OR
you can use onCell Edit and stop the update, something like this
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
if (!((g_user.hasRoleExactly("service_desk")) || (g_user.hasRoleExactly("incident_manager")) || (g_user.hasRoleExactly("major_incident_manager")))) {
if (newValue.toString() == '1' || newValue.toString() == '2')
alert('Please contact Service Desk to raise priority to Critical or Crisis');
saveAndClose = false;
} else {
saveAndClose = true;
}
callback(saveAndClose);
}
OR
you can use before update business rule
Condition:
Priority Changes to 1 OR Priority Changes to 2 && !((gs.hasRole("service_desk")) || (gs.hasRole("incident_manager")) || (gs.hasRole("major_incident_manager")))
Script:
(function executeRule(current, previous) { // Add your code here
gs.addErrorMessage('Please contact Service Desk to raise priority to Critical or Crisis');
current.setAbortAction(true);
})(current, previous);
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
05-06-2025 11:15 PM
Add console.log statements to both the Business Rule and Client Script to check if they are being executed and if the roles are being correctly identified.
2nd alternative:
Go with client script only instead of Display BR
use g_form.hasRoleExaclty() method to check the required roles and remove options based for no role found.
If my response helped, please mark it correct and close the thread so that it benefits future readers.
Regards,
Mohd Arbaz.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 11:21 PM
Why not use g_user.hasRoleExactly() in client side and handle the logic?
Check script shared by @Vasantharajan N
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
05-07-2025 02:11 AM
@Ankur Bawiskar That is working i before but the problem is user still able to change the impact and urgency through List view .can you guide me to solution for that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 02:21 AM
you can use list_edit ACLs on those 2 fields to block the field from getting updated in list
OR
you can use onCell Edit and stop the update, something like this
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
if (!((g_user.hasRoleExactly("service_desk")) || (g_user.hasRoleExactly("incident_manager")) || (g_user.hasRoleExactly("major_incident_manager")))) {
if (newValue.toString() == '1' || newValue.toString() == '2')
alert('Please contact Service Desk to raise priority to Critical or Crisis');
saveAndClose = false;
} else {
saveAndClose = true;
}
callback(saveAndClose);
}
OR
you can use before update business rule
Condition:
Priority Changes to 1 OR Priority Changes to 2 && !((gs.hasRole("service_desk")) || (gs.hasRole("incident_manager")) || (gs.hasRole("major_incident_manager")))
Script:
(function executeRule(current, previous) { // Add your code here
gs.addErrorMessage('Please contact Service Desk to raise priority to Critical or Crisis');
current.setAbortAction(true);
})(current, previous);
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
05-06-2025 11:33 PM
Hello @VijayKummamuru ,
Your scripts are working fine, assuming that the purpose is the following:
If the user has at least one of the three roles it won't do anything but if the user has none of these roles then the Impact options get removed.
How are you testing this?
Check by impersonating a user who has one of the three roles.
Then check by impersonating a user who has none of them.
Regards,
Robert