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

first, try use a background script to execute and check if your script is returning the values as expected. 

 

Hi,

 

I have written this-

answer = checkState();

function checkState() {
var gr = new GlideRecord('u_physical_security_task');
gr.addQuery('parent', '75a002b38725cd102ad9840acebb35a1');   //sys_id is of Parent record
gr.query();
if(gr.next()) {
if (gr.state + "" == '3') {
gs.info("Rekha "+ gr.state);
return 'yes';
}
}
return 'no';
}

 

It is giving log info as 3 while task sate is Open. What is wrong here. Please advise.

then please check what is the actual state value of the close complete. it might be also a issue.

or try writing the code as below in background script 

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.hasNext()) {
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';

please execute the above script in the function in background script and paste the results here 

Hi, 

After running your script-

 find_real_file.png

Yes, State value for Closed Complete is 3-

find_real_file.png

 

 

My bad. i missed the string quotes in my script

 

try the below script and check

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.hasNext()) {
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';