Report on all Open RITMS but all the related sctasks are closed

Sravani2
Tera Contributor

Hello everyone,

I'm trying to get a list of RITMs where all the related sctasks are closed but RITM is still in open state.

I'm not able to get this through report. Can you please suggest a way to get the output.

Thanks,Sravani

1 ACCEPTED SOLUTION

Hi,

So you will have to go with script approach

Script Include: It should be client callable

var ReportUtils = Class.create();
ReportUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getRITM:function(){
		var arr = [];
		var gr = new GlideRecord("sc_req_item");
		gr.addEncodedQuery("state=1"); // state is open
		gr.query();
		while(gr.next()) {
			var closedCount = 0;
			var taskRec = new GlideRecord("sc_task");
			taskRec.addQuery("request_item", gr.sys_id);
			taskRec.query();
			var totalCount = taskRec.getRowCount();
			while(taskRec.next()){
				if(taskRec.active.toString() == 'false'){
					closedCount++;
				}
			}

			if(closedCount == totalCount && totalCount != 0){
				// if count is same then all tasks are closed then push RITM sys_id in array
				arr.push(gr.getValue('sys_id'));
			}
		}
		return arr.toString();

	},

	type: 'ReportUtils'
});

Condition of Report

sys_id [IS ONE OF] javascript: new ReportUtils().getRITM();

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

23 REPLIES 23

Hi,

So it is working as per expected from your original question right

Show those closed SC Tasks here it would be 9 for that open RITM

Did your requirement get changed?

I believe I answered your original question to list of RITMs where all the related sctasks are closed but RITM is still in open state.

If yes please mark my response as correct and helpful

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

The requirement is same - list of open RITMs where all the related sctasks are closed.

I've have an output now, that shows only sctaks which are closed in RITM.

I was looking for the open RITMS where all related sctasks are closed.

According to the above example: Where there are 10 sctasks for one RITM(let's say RITM123)

I should get RITM123 in my list only when all the 10 sctasks(not few) are closed but still the RITM is open

 

Hi,

So you will have to go with script approach

Script Include: It should be client callable

var ReportUtils = Class.create();
ReportUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getRITM:function(){
		var arr = [];
		var gr = new GlideRecord("sc_req_item");
		gr.addEncodedQuery("state=1"); // state is open
		gr.query();
		while(gr.next()) {
			var closedCount = 0;
			var taskRec = new GlideRecord("sc_task");
			taskRec.addQuery("request_item", gr.sys_id);
			taskRec.query();
			var totalCount = taskRec.getRowCount();
			while(taskRec.next()){
				if(taskRec.active.toString() == 'false'){
					closedCount++;
				}
			}

			if(closedCount == totalCount && totalCount != 0){
				// if count is same then all tasks are closed then push RITM sys_id in array
				arr.push(gr.getValue('sys_id'));
			}
		}
		return arr.toString();

	},

	type: 'ReportUtils'
});

Condition of Report

sys_id [IS ONE OF] javascript: new ReportUtils().getRITM();

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Sravani 

Hope you are doing good.

Did you get a chance to check on the solution provided to resolve your query?

If your query is resolved please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks Ankur, this has worked perfectly for my requirements