- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 10:12 PM
1) when i update the state of sctask to any, then I need to update the state of RITM and REQ and Universal request too?
2) When I update the work notes or additional comments of sctask it should update on RITM and on Universal request too?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 03:10 AM
It's working now like this
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var closedCompleteCount = 0;
var closedInCompleteCount = 0;
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.query();
var totalCount = gr.getRowCount();
while(gr.next()){
if(gr.state == 3){
closedCompleteCount++;
}
if(gr.state == 4){
closedInCompleteCount++;
}
}
var ritm = current.request_item.getRefRecord();
var req = current.request.getRefRecord();
if(totalCount == closedCompleteCount){
ritm.state = 3;
ritm.update();
req.state = 3;
req.update();
}
if(closedInCompleteCount > 0){
ritm.state = 4;
ritm.update();
req.state = 4;
req.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 12:12 AM
Is your issue resolved?
If yes, feel free to mark correct so it ends up in resolved queue and also will be helpful for someone looking for similar queries.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 01:49 AM
Hello
I am talking about state not about stage
i am confused what to do.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 01:56 AM
I know state is something that you need to close, also you need to set state as well, that's what I have mentioned in your other post.
STATE and STAGE both are fields on on your RITM form, both has to updated in order to the Request to be closed
Check the condiiton of the BR:
current.stage.changes() && (current.stage=='complete' || current.stage=='Request Cancelled' || current.stage == "closed_incomplete" || current.stage=="closed_skipped")
Just add the line as I have suggested above, it will work for you
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 02:27 AM
Hello
I updated the code as u mentioned. but it's not working for closed_complete. it's only working for closed_incomplete
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var closedCompleteCount = 0;
var closedInCompleteCount = 0;
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.query();
var totalCount = gr.getRowCount();
while(gr.next()){
if(gr.state == 3){
closedCompleteCount++;
}
if(gr.state == 4){
closedInCompleteCount++;
}
}
var ritm = current.request_item.getRefRecord();
if(totalCount == closedCompleteCount){
ritm.state = 3;
ritm.stage = "closed_complete";//update stage on RITM as complete
ritm.update();
}
if(closedInCompleteCount > 0){
ritm.state = 4;
ritm.stage = "closed_incomplete";//update stage on RITM as incomplete
ritm.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 02:31 AM
Look closely its "completed" and not "closed complete"
ritm.stage = "complete";//update stage on RITM as complete
ritm.stage = "closed_incomplete";//update stage on RITM as incomplete
current.stage.changes() && (current.stage=='complete' || current.stage=='Request Cancelled' || current.stage == "closed_incomplete" || current.stage=="closed_skipped")
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar