RITM should get close once all catalog tasks are closed

tulasi8
Tera Contributor

Hi Community,

 

I want the RITM should get close only once all the catalog tasks are closed. I have written the business rule for this after update with the condition as state is closed complete.  But it's not working as per requirement. Can anyone please help on this. 

 

    var gr = new GlideRecord("sc_task");
    gr.addActiveQuery();
    gr.addQuery("request_item", current.request_item);
    gr.setLimit(1);
    gr.query();
    if (!gr.hasNext()) {
        var ritm = current.request_item.getRefRecord();
        ritm.state = current.state;
        ritm.update();
    }
 
Thanks,
Tulasi.
15 REPLIES 15

Badrinarayan
Tera Guru

Hi @tulasi8 

you can use after update BR on sc_task

Condition: State [IS ONE OF] Closed Complete/Closed Incomplete AND Request Item.Item == Your Catalog Item

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord('sc_task');
	gr.addQuery('request_item', current.request_item); 
	gr.addQuery('active', true);
	gr.query();
	if(!gr.next()){
		var ritm = current.request_item.getRefRecord(); 
		ritm.state = 3;
		ritm.update();
	}

})(current, previous);

 

if your issue is resolved, mark as helpful and accept the solution

Thanks regards

Badrinarayan

@Badrinarayan 

I have already given those conditions only 

tulasi8_0-1752153957678.png

 

Hi,

The script is working fine on my end. Please review it once and also check the backend values, specifically for statuses like Closed Complete and Incomplete.

Also, I noticed you're using hasNext() to check for records. It's better to use next() instead, as it both checks for the existence of a record and moves the pointer forward.

Thanks & Regards,
Badri

@Badrinarayan these are the actions i have given in flow designer, are these actions after creating task is needed even after writing the business rule ?

tulasi8_0-1752154460375.png