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

James Chun
Kilo Patron

Hi @Ria,

 

Can you also share your Flow as well?

 

And in regards to the BR, I am assuming that it's on the SCTASK table?

Is this a custom BR and what happens if you deactivate it?

 

Cheers

Ria
Tera Contributor

Hi James,

 

Yes, a business rule is created on the sc_task table that runs after an update. If I deactivate the Business Rule, my Flow Designer works correctly, but I can't deactivate it because it is necessary for other catalog items.

Hi @Ria 

 

You can add one more condition on field of Business rule so that not to run for particular catalog item

Bhavya11_1-1719384358675.png

 

in property you can store the sysid of  catalog item then add the condition so that it wont run that Business rule for those catalog task belongs to the that item

 

 

condition - current.state.changes() && (current.state == 3 || current.state ==7) && current.request_item.cat_item !=gs.getProperty('catalog_item_id')

 

 

If my answer helped you in any way, please then mark it as helpful or correct.

 

Thanks,

BK

Ria
Tera Contributor

Hi Bhavya,

 

I added the condition and it works well, but if someone manually adds a task, the RITM does not close.

 

Regards,

Riya Jain