- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 12:58 AM
I want to modify the script below, I want to update the state only when the existing sc task state is not closed complete or closed incomplete or closed skipped when the result ==2 and I want to update the state when the existing sc task state is not closed incomplete or closed skipped when the result ==3. Can anyone help me with the modified script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 01:06 AM
Hello @GBS
Try this
function updateSCTask(sys_id, result) {
var gr = new GlideRecord("sc_task");
if (gr.get(sys_id)) {
// When result is 2, update the state to 8 if the current state is not closed states (8, 7, or 6)
if (result == "2" && gr.getValue("state") != 8 && gr.getValue("state") != 7 && gr.getValue("state") != 6) {
gr.setValue("state", "8"); // Set state to Closed Complete (8)
gr.setValue("u_on_hold_reason", 3); // Set the on-hold reason if applicable
gr.setValue("follow_up", gs.daysAgo(-7)); // Set follow-up date
}
// When result is 3, update the state to 3 if the current state is not closed states (7 or 6)
if (result == "3" && gr.getValue("state") != 7 && gr.getValue("state") != 6) {
gr.setValue("state", "3"); // Set state to In Progress (3)
}
gr.update(); // Save the record after updates
}
}
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 01:06 AM
Hello @GBS
Try this
function updateSCTask(sys_id, result) {
var gr = new GlideRecord("sc_task");
if (gr.get(sys_id)) {
// When result is 2, update the state to 8 if the current state is not closed states (8, 7, or 6)
if (result == "2" && gr.getValue("state") != 8 && gr.getValue("state") != 7 && gr.getValue("state") != 6) {
gr.setValue("state", "8"); // Set state to Closed Complete (8)
gr.setValue("u_on_hold_reason", 3); // Set the on-hold reason if applicable
gr.setValue("follow_up", gs.daysAgo(-7)); // Set follow-up date
}
// When result is 3, update the state to 3 if the current state is not closed states (7 or 6)
if (result == "3" && gr.getValue("state") != 7 && gr.getValue("state") != 6) {
gr.setValue("state", "3"); // Set state to In Progress (3)
}
gr.update(); // Save the record after updates
}
}
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 01:26 AM
@Juhi Poddar thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 01:28 AM
Hello @GBS
Glad that the issue is resolved.
You can also mark it as an accepted solution.
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 02:25 AM
try this once
function updateSCTask(sys_id, result) {
var gr = new GlideRecord("sc_task");
if (gr.get(sys_id)) {
var state = gr.getValue("state");
if (result == "2" && state != 8 && state != 4 && state != 5 && state != 7) {
gr.setValue("state", "8");
gr.setValue("u_on_hold_reason", 3);
gr.setValue("follow_up", gs.daysAgo(-7));
}
if (result == "3" && state != 3 && state != 5 && state != 7) {
gr.setValue("state", "3");
}
gr.update();
}
}
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