Trying to create new client script for Major Incidents
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2022 09:28 AM
Hello, I am trying to create a new client script that allows users with the 'major_incident_manager' role the ability to ONLY close major incidents. I am basing it off the current script in the OOB client script "(BP) Hide Choice - Closed" but I am not having much luck with the script.
Basically, the script needs to check 2 things:
1) if g_form.getValue('major_incident_state') == 'accepted'
2) if g_user.hasRole('major_incident_manager')
If both of these match, the statement should end and nothing should happen.
If it doesn't match (meaning it's either a regular incident or the user does not have the appropriate role), then the OOB script should apply as below:
if (g_form.getValue('incident_state') != '7')
g_form.removeOption('incident_state', 7);
if (g_form.getValue('state') != '7')
g_form.removeOption('state', 7);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2022 10:10 AM - edited ‎11-29-2022 10:12 AM
Hi @astruphar
You can try onload client script : verify all field and back-end values (script is not tested )
if((!g_user.hasRole('major_incident_manager')&& (!g_form.getValue('major_incident_state') == 'accepted' )){
if (g_form.getValue('incident_state') != '7'){
g_form.removeOption('incident_state', '7');
}
if (g_form.getValue('state') != '7'){
g_form.removeOption('state', '7');
}
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2022 10:58 AM
Hi Gunjan,
I was able to use your suggestion to create the following script:
function onLoad() {
if ((!g_user.hasRole('major_incident_manager') && (!g_form.getValue('major_incident_state') == 'accepted')))
return;
if (g_form.getValue('incident_state') != '7')
g_form.removeOption('incident_state', 7);
if (g_form.getValue('state') != '7')
g_form.removeOption('state', 7);
}
However, it is still hiding the Closed (7) choice when I'm on a major incident record. Any suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2022 11:02 AM
If we are not doing anything by checking role and and state accepted or not then no need to writedown that conditions. You can remove first if block.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2022 11:08 AM
It was my understanding that if you use an 'if' statement and end it with 'return', if those conditions are met then the script ends and it won't continue past the return. Is that correct?