- 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 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 03:19 AM
You are force closing it and not following OOB BR, you could have easily hardcoded it and even I could have suggested that, but you are building an unnecessary update and force closing the request and it is not the right approach in my view, but revisit this, once you gain more ideas how to incorporate OOB functionality with your process
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 10:38 PM
Since you can have multiple tasks to fulfill 1 request, it would be strange to close the request as soon as a task is closed. You need logic behind this. Please elaborate on what you are trying to achieve. What is your use case?
If my answer helped you in any way, please then mark it as helpful.
Mark
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 10:43 PM
my scenario is like , if we have multiple sc_task (or) if we have only one sc_task under one ritm, if all the sc_task state is closed complete then only ritm state is closed complete otherwise it should remain in closed incomplete.
And one more thing i need to mention here is that we have universal request too.
that means along with Req and ritm we need to update universal request too
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2022 05:54 AM
When I update the paintings notes or additional comments of sctask it should update on RITM and on Universal request too? Cow Squishmallows