- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 01:37 AM
I need to update the REQ state to closed complete when RITM state is closed complete.
currently if state of sc_task is closed then RITM state is setting as closed complete.
So as well as RITM i need to closed Request also if RITM is closed.
Any help will be appreciated.
Thank you,
Shivprasad
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 02:47 AM
Hi,
then add the logic there itself where you are closing RITM
update as 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 = 3;
req.update();
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 01:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 02:47 AM
Hi,
then add the logic there itself where you are closing RITM
update as 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 = 3;
req.update();
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 01:42 AM
If we are having 3 tasks one task in Close Complete and 2. Close Incomplete and 3. open
but with this condition when one task is close incomplete then the related request and RITM are getting closed .
if(closedInCompleteCount > 0){
ritm.state = 4;
ritm.update();
req.state = 3;
req.update();
}