- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 09:17 AM
Hello everyone,
I'm currently trying to achieve the following, regarding status modification at sc_request table:
• When the status is Open – The only available options should be: Awaiting approval, Pending, In Progress, and Canceled
• When the status is Awaiting approval - The only available options should be: Open, Closed;
• When the status is In progress – The only available options should be: Resolved, Pending and Canceled;
• When the status is Pending – The only available option should be In progress;
• When Closed and Canceled – No available options;
Could anyone help me on how this should be done? I'm relatively new at ServiceNow.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 05:21 PM
1) I can see your script is active false please make it true
2) Please ensure that you have mapped the correct backend values for the choices
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 10:23 AM
Hello @Alex-Lima84 ,
You cna achieve this by using the client script.
You add the conditions in if else loop and remove or add the choice options
Please check the below link which will help you
Thanks,
Omkar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 10:31 AM
You need to use "addOption" or "removeOption" functions just to add and remove value from the choice field!
syntax of addOption - g_form.addOption('Name_of_the_field', "backend_name_of_choice", "label_of_choice")
syntax of removeOption - g_form.removeOption('Name_of_the_field', 'backend_name_of_choice');
Here is an example of your case, I have built some conditions, please continue according to you scenarios:
Write a on change client script onchange of state and paste the code as below:
if(newValue == "open"){
g_form.addOption("state","awaiting_approval","Awaiting approval");
g_form.addOption("state","pending","Pening");
g_form.addOption("state","in_progress","In Progress");
g_form.addOption("state","canceled","Canceled");
g_form.removeOption("state","resolved");
g_form.removeOption("state","closed");
}
else if(newValue == "awaiting_approval"){
g_form.removeOption("state","awaiting_approval","Awaiting approval");
g_form.removeOption("state","pending","Pening");
g_form.removeOption("state","in_progress","In Progress");
g_form.removeOption("state","canceled","Canceled");
g_form.removeOption("state","resolved");
g_form.addOption("state","closed","Closed");
g_form.addOption("state","open","Open");
}
else if(newValue == "in_progress"){
}
else if(newValue == "pending"){
}
else if(newValue == "canceled"){
}
Note: Please check the backend names of the choice according to your instance as sometimes these have been customize in everbody's instance.
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 10:57 AM
You marked my answer helpful!
Please Accept the solution, if it has answered your query, it would be beneficial for future readers too 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 11:57 AM
Thank you for your answer.
I did as per below, but it's not working:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if(newValue == "open"){
g_form.addOption("state","requested","Awaiting Approval");
g_form.addOption("state","pending","Pending");
g_form.addOption("state","in_progress","In Progress");
g_form.addOption("state","cancelled","Cancelled");
g_form.removeOption("state","open");
g_form.removeOption("state","resolved");
g_form.removeOption("state","in_process");
g_form.removeOption("state","closed_complete");
g_form.removeOption("state","closed_incomplete");
g_form.removeOption("state","closed_cancelled");
g_form.removeOption("state","closed_rejected");
g_form.removeOption("state","closed_skipped");
}
if(newValue == "requested"){
g_form.addOption("state","closed_complete","Closed Complete");
g_form.addOption("state","closed_incomplete","Closed Incomplete");
g_form.addOption("state","closed_cancelled","Closed Cancelled");
g_form.addOption("state","closed_rejected","Closed Rejected");
g_form.addOption("state","closed_skipped","Closed Skipped");
g_form.addOption("state","open","Open");
g_form.removeOption("state","resolved");
g_form.removeOption("state","requested");
g_form.removeOption("state","in_process");
g_form.removeOption("state","pending");
g_form.removeOption("state","in_progress");
g_form.removeOption("state","cancelled");
}
if(newValue == "in_progress"){
g_form.addOption("state","resolved", "Resolved");
g_form.addOption("state","pending","Pending");
g_form.addOption("state","cancelled","Cancelled");
g_form.removeOption("state","requested");
g_form.removeOption("state","in_progress");
g_form.removeOption("state","open");
g_form.removeOption("state","in_process");
g_form.removeOption("state","closed_complete");
g_form.removeOption("state","closed_incomplete");
g_form.removeOption("state","closed_cancelled");
g_form.removeOption("state","closed_rejected");
g_form.removeOption("state","closed_skipped");
}
if(newValue == "closed_complete" || newValue == "closed_incomplete" || newValue == "closed_cancelled" || newValue == "closed_rejected" || newValue == "closed_skipped" || newValue == "cancelled"){
g_form.removeOption("state","resolved");
g_form.removeOption("state","pending");
g_form.removeOption("state","cancelled");
g_form.removeOption("state","requested");
g_form.removeOption("state","in_progress");
g_form.removeOption("state","open");
g_form.removeOption("state","in_process");
g_form.removeOption("state","closed_complete");
g_form.removeOption("state","closed_incomplete");
g_form.removeOption("state","closed_cancelled");
g_form.removeOption("state","closed_rejected");
g_form.removeOption("state","closed_skipped");
}
}