How to auto close Request if no action taken after 2 days of Date of Dispatch field?

Rekha Tiwari
Kilo Guru

Hi Team,

I have a Record Producer which is mapping to a table u_physical_security.

Record Producer is having a variable called Date of Dispatch this variable is mapped to u_physical_security table's field Date of Dispatch.

Workflow running for this RP is having three level of approvals and multiple catalog tasks. First approval generated - It got approved then 2nd approval generated - t got approved the 3rd approval generated. After that tasks generated for u_physical_security_task.

 

My requirement is-  If no action is taken after 2 days of Date of Dispatch field then auto close the Physical Security Task and Physical security request.

This action can be on any level of approvals or tasks-  If no action is taken on approval  after 2 days of Date of dispatch then set approval as No longer required and auto close Physical security request. 

if first approval is approved and then no action is taken after 2 days of Date of dispatch on 2nd approval then set approval as No longer required and auto close Physical security request. 

If all approval approved and task generated then if no action is taken after 2 days of Date of dispatch on2nd task then close Physical security task and Physical security request.

 

Please help me to get this 

21 REPLIES 21

Ohh I see,

 

Yes, this is the output-

 

find_real_file.png

as you can see. that a reccord is still pending.

also  copy the first input that is a encoded query and paste it in you table to see the result for it

or execute the below script to get the sys_id of the child record that is still pending

 

var gr = new GlideRecord('u_physical_security_task');
gr.addQuery('parent', '75a002b38725cd102ad9840acebb35a1');   //sys_id is of Parent record
gr.addQuery('state','!=','3'); // checking if any records with state is not 3
gr.query();
gs.info(gr.getEncodedQuery());
if(gr.next()) {
gs.info("still record is pending. " +gr.sys_id);//printing the sys_id of the open task
return 'no' 
}
gs.info('all tasks are close')
return 'yes';

Yes, it is giving correct sys_id of child record.

find_real_file.png

But why still it is going in Yes branch of If condition

answer = checkState();

function checkState() {
var gr = new GlideRecord('u_physical_security_task');
gr.addQuery('parent', '75a002b38725cd102ad9840acebb35a1');   //sys_id is of Parent record
gr.addQuery('state','!=','3'); // checking if any records with state is not 3
gr.query();
if(gr.next()) {
return 'no' 
}
return 'yes';

}

add this in your if condition acitvity.  then it should work