- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 10:18 AM
Hi, I am trying to setup some logic to stop users from opening a new incident record and then closing it as resolved. We want a new incident record to only be open as "New" or In "Progress". Happy to either stop the State field from showing the options in the first place until ticket has been moved to "In Progress", or create a field alert to let them know it cannot be set as resolved from a new state.
I would like assistance with the script that would need to be used within an on client script. I could aslo do via a busienss rule but that will require the users to fill out the form and submit the ticket for the error to bounce back.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 10:31 AM
You can do this via an Onload script on the incident table with something like this:
function onLoad() {
if (g_form.isNewRecord()) {
g_form.clearOptions('state');
g_form.addOption('state', '1', 'New');
g_form.addOption('state', '2', 'In Progress');
}
}
I hope this helps!
If this was helpful, or correct, please be kind and mark the answer appropriately.
Michael Jones - Proud member of the GlideFast Consulting Team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 11:40 AM
I would suggest using the State Flows table Use state flows. You would just create the records where the states can move from new and so on
Thanks,
David Whaley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 12:14 PM
Thanks for raising this, I have not seen this before but good to know for future reference. I am happy with the solution I currently have in place.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 10:57 AM
Hi Jacob,
You can use below change client script which will work both onChange and onLoad :- Remove choices as per your requirement.:- On Change of state
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
if (g_form.getValue('state') == 1) {
g_form.removeOption('state', '3');
g_form.removeOption('state', '6');
g_form.removeOption('state', '7');
g_form.removeOption('state', '8');
}
return;
}
//Type appropriate comment here, and begin script below
if (newValue == 2) {
g_form.addOption('state', '1','New',1);
g_form.addOption('state', '2','In Progress',2);
g_form.addOption('state', '3','On Hold',3);
g_form.addOption('state', '6','Resolved',4);
g_form.addOption('state', '7','Closed',5);
g_form.addOption('state', '8','Canceled',6);
}
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Gunjan Kiratkar
Consultant - ServiceNow, Cloudaction
Rising Star 2022
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
‎04-05-2022 10:59 AM
Output:-
New Incident:-
When the state moves to in progress:-