The CreatorCon Call for Content is officially open! Get started here.

If all catalog task are closed complete then the related RITM should be closed(Only Scheduled job)

Avinash16
Tera Contributor

Hello All,

 

I need to create a Scheduled job to close the RITM for one particular catalog item only, when all the catalog task are closed then RITM should be closed.

 

Note: The catalog item has 5 catalog tasks

 

Thanks in Advance

Avinash

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Avinash16 

something like this. I hope you can enhance it further.

closeRITM();

function closeRITM(){
	try{
		var gr = new GlideRecord("sc_req_item");
		gr.addActiveQuery();
		gr.addQuery("cat_item.name", "Your Catalog Item Name Here");
		gr.addQuery("name", "value");
		gr.query();
		while (gr.next()) {

			var taskRec = new GlideRecord("sc_task");
			taskRec.addActiveQuery();
			taskRec.addQuery("request_item", gr.getUniqueValue());
			taskRec.setLimit(1);
			taskRec.query();
			if(!taskRec.hasNext()){
				// there are no active tasks for this RITM so close it
				gr.state = 3;
				gr.active = false;
				gr.update();	
			}
		}
	}
	catch(ex){
		gs.info(ex);
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Avinash16 

so what script did you start with?

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Avinash16 

something like this. I hope you can enhance it further.

closeRITM();

function closeRITM(){
	try{
		var gr = new GlideRecord("sc_req_item");
		gr.addActiveQuery();
		gr.addQuery("cat_item.name", "Your Catalog Item Name Here");
		gr.addQuery("name", "value");
		gr.query();
		while (gr.next()) {

			var taskRec = new GlideRecord("sc_task");
			taskRec.addActiveQuery();
			taskRec.addQuery("request_item", gr.getUniqueValue());
			taskRec.setLimit(1);
			taskRec.query();
			if(!taskRec.hasNext()){
				// there are no active tasks for this RITM so close it
				gr.state = 3;
				gr.active = false;
				gr.update();	
			}
		}
	}
	catch(ex){
		gs.info(ex);
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Kudos Ankur !