- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 12:49 AM
Hi Team,
Suppose i have a RITM which have more than 1 task and i need to change the state of RITM based on sc task .
if any of task move to WIP then state of RITM move to WIP
If any of the task move to pending then state of RITM move to pending
When all task are close complete then only state change to close complete of RITM
When state of any task changes to closed skipped or incomplete then state of RITM changed to close incomplete .
How to achieved this using Script?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 12:54 AM
Create a Business Rule on the sc_task table
Trigger Conditions: Set it to run on update when the state field changes.
When to Run: Use After.
Filter Conditions: State Changes
(function executeRule(current, previous /*null when async*/) {
// Get the parent RITM (Requested Item)
var ritm = current.request_item.getRefRecord();
// If no RITM found, exit
if (!ritm) return;
// Flag to track tasks
var hasWip = false;
var hasPending = false;
var hasClosedIncomplete = false;
var allClosedComplete = true;
// Query all tasks related to the RITM
var taskGr = new GlideRecord('sc_task');
taskGr.addQuery('request_item', ritm.sys_id);
taskGr.query();
while (taskGr.next()) {
// Skip the current task as its state has already changed
if (taskGr.sys_id == current.sys_id) {
taskGr.state = current.state;
}
// Check states
if (taskGr.state == 2) { // WIP (Work in Progress)
hasWip = true;
} else if (taskGr.state == 3) { // Pending
hasPending = true;
} else if (taskGr.state == 8 || taskGr.state == 9) { // Closed Skipped or Closed Incomplete
hasClosedIncomplete = true;
} else if (taskGr.state != 4) { // Not Closed Complete
allClosedComplete = false;
}
}
// Determine the RITM state based on conditions
if (hasClosedIncomplete) {
ritm.state = 9; // Closed Incomplete
} else if (hasWip) {
ritm.state = 2; // WIP
} else if (hasPending) {
ritm.state = 3; // Pending
} else if (allClosedComplete) {
ritm.state = 4; // Closed Complete
}
// Update the RITM if state has changed
ritm.update();
})(current, previous);
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 01:40 AM
@kun1 Yes only on state change on sc_task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 02:26 AM
Thanks. Will check and let you know in case of any issues

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 02:59 AM
@kun1 Don't forget to mark the response an accepted solution if it works for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 02:25 AM
As of now its working fine for a single sctask and i dont have multiple task generated RITM so i am marking as correct.Will connect if its not wokring for multiple sc task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 01:02 AM
Hello @kun1 ,
You can use the logic given here. Use lookup records actions with your conditions. Then, as per the requirement, update your state of RITM.
If you have any questions, please let me know.
Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.
Thanks and Regards,
Ashish