- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 09:10 AM
Hello,
I am trying to close the REQ which has multiple RITM's. If one of the RITM is 'closed incomplete' or 'closed skipped' then the REQ should be 'closed incomplete' else 'closed incomplete'. I am writing below BR however it is not working.
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideAggregate('sc_req_item');
gr.addQuery('request', current.request);
gr.addAggregate('COUNT');
gr.query();
var count=0;
if (gr.next()) {
count=gr.getAggregate('COUNT'); //Get all task count
}
var glideRITM = new GlideAggregate('sc_req_item');
glideRITM.addQuery('request',current.request);
glideRITM.addQuery('state','3'); //Get Closed complete task count
glideRITM.addAggregate('COUNT');
glideRITM.query();
var closedTaskCount=0;
if (glideRITM.next()) {
closedTaskCount=glideRITM.getAggregate('COUNT');
var glideRequest=current.request.getRefRecord();
if(count==closedTaskCount){
glideRequest.setValue('state','closed_complete'); //close the request if count of all task and closed task same.
glideRequest.update();
}
else{
glideRequest.setValue('state','closed_incomplete'); //close the request if count of all task and closed task same.
glideRequest.update();
}
}
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 09:16 AM
@Karishma Dubey Here is the updated BR.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideAggregate('sc_req_item');
gr.addQuery('request', current.request);
gr.addAggregate('COUNT');
gr.query();
var Totaltaskcount = 0;
if (gr.next()) {
Totaltaskcount = gr.getAggregate('COUNT'); //Get all task count
}
gs.log('count ' + count);
var glideRITM = new GlideAggregate('sc_req_item');
glideRITM.addQuery('request', current.request);
// glideRITM.addQuery('state', '3'); //Get Closed complete task count
//glideRITM.addEncodedQuery('stateIN3,4,7');
//glideRITM.addAggregate('COUNT');
glideRITM.addAggregate('COUNT', 'state');
glideRITM.groupBy('state');
//glideRITM.groupBy('state');
glideRITM.query();
var closedTaskCount = 0;
var stateobj = {};
while (glideRITM.next()) {
//gs.print('state '+glideRITM.getDisplayValue('state')+" count "+glideRITM.getAggregate('COUNT','state'));
stateobj[glideRITM.getValue('state')] = glideRITM.getAggregate('COUNT', 'state');
}
if(stateobj){
var closedTaskcount = stateobj['Closed Complete'];
var closedIncomTaskcount = stateobj['Closed Incomplete'];
var closedSkipTaskcount = stateobj['Closed Skipped'];
var glideRequest = current.request.getRefRecord();
if(Totaltaskcount==parseInt(closedTaskcount)){
glideRequest.setValue('state', '3');
glideRequest.setValue('request_state', 'closed_complete');
glideRequest.update();
}
else if(Totaltaskcount==parseInt(closedTaskcount)+parseInt(closedIncomTaskcount)+parseInt(closedSkipTaskcount)){
glideRequest.setValue('state', '4');
glideRequest.setValue('request_state', 'closed_incomplete');
glideRequest.update();
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 09:16 AM
@Karishma Dubey Here is the updated BR.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideAggregate('sc_req_item');
gr.addQuery('request', current.request);
gr.addAggregate('COUNT');
gr.query();
var Totaltaskcount = 0;
if (gr.next()) {
Totaltaskcount = gr.getAggregate('COUNT'); //Get all task count
}
gs.log('count ' + count);
var glideRITM = new GlideAggregate('sc_req_item');
glideRITM.addQuery('request', current.request);
// glideRITM.addQuery('state', '3'); //Get Closed complete task count
//glideRITM.addEncodedQuery('stateIN3,4,7');
//glideRITM.addAggregate('COUNT');
glideRITM.addAggregate('COUNT', 'state');
glideRITM.groupBy('state');
//glideRITM.groupBy('state');
glideRITM.query();
var closedTaskCount = 0;
var stateobj = {};
while (glideRITM.next()) {
//gs.print('state '+glideRITM.getDisplayValue('state')+" count "+glideRITM.getAggregate('COUNT','state'));
stateobj[glideRITM.getValue('state')] = glideRITM.getAggregate('COUNT', 'state');
}
if(stateobj){
var closedTaskcount = stateobj['Closed Complete'];
var closedIncomTaskcount = stateobj['Closed Incomplete'];
var closedSkipTaskcount = stateobj['Closed Skipped'];
var glideRequest = current.request.getRefRecord();
if(Totaltaskcount==parseInt(closedTaskcount)){
glideRequest.setValue('state', '3');
glideRequest.setValue('request_state', 'closed_complete');
glideRequest.update();
}
else if(Totaltaskcount==parseInt(closedTaskcount)+parseInt(closedIncomTaskcount)+parseInt(closedSkipTaskcount)){
glideRequest.setValue('state', '4');
glideRequest.setValue('request_state', 'closed_incomplete');
glideRequest.update();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 09:21 AM
@Karishma Dubey Please refer the below link similar to your requirement,
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
Sujatha V.M.