- 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-12-2025 04:15 AM
Thank you for marking my response as helpful.
As per new community feature you can mark multiple responses as correct.
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
01-21-2025 12:29 AM
Can you check my below comment?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader