Flow Designer wait for catalog tasks to close before updating Request state to closed complete.

Ria
Tera Contributor

Hello,

 

Currently, once the request is created and approved, one task gets generated. After the first task is closed, a second task is created. The requirement is to change the RITM state to "Closed Complete" only when the second task is closed. However, in my case, the RITM state changes to "Closed Complete" immediately after the first task is closed, and then the second task gets created. Can someone please help? This issue might be due to an existing business rule for all catalog items. Please see the script below.

 
condition - current.state.changes() && (current.state == 3 || current.state ==7) 
script -
current.active = false;
current.work_end = nowDateTime();
current.business_duration = gs.calDateDiff(current.work_start.getDisplayValue(),current.work_end.getDisplayValue(),false);
 
var flag=0;
var gr_tsk = new GlideRecord("sc_task");
gr_tsk.addQuery('request_item', current.request_item);
gr_tsk.addQuery('state','3');
gr_tsk.query();
if (gr_tsk.next()){
flag =1;}
 
var gr_t = new GlideRecord("sc_task");
gr_t.addQuery('request_item', current.request_item);
gr_t.addQuery('state','NOT IN', '3,7'); // Not closed complete ,closed skipped
gr_t.query();
if(!gr_t.next()){
updateRITMState();}
 
function updateRITMState(){  
     var gr = new GlideRecord('sc_req_item');  
     gr.addQuery('sys_id',current.request_item);  
gr.addQuery('stage','!=','waiting_for_approval');  
 
     gr.query();  
     if(gr.next()){
if (flag == 1){
gr.state = 3;}
else{
gr.state = current.state;
}
gr.update();}}

 

5 REPLIES 5

Hi @Ria,

 

Thanks, so the issue is due to the Business Rule.

 

I guess a quick win would be adding a condition to the BR to ensure it doesn't run on specific conditions.

But if I were you, I would consider refactoring the Business Rule.

There must be a business requirement behind the BR and you need to understand it before modifying it. Also, the BR is not well-written nor it's not very clear what it's trying to achieve.