How to close a task in a workflow after 5 minutes

Alessa
Mega Guru

Hello community I need help:

I need to close a task in a workflow after 5 minutes (I attached a reference photo, please see it). I have read that you can use a timer, wait for condition and set value, but I don't know how to use them so that the first task closes after 5 minutes. Please I need a graphic answer (step by step) so I can achieve this. Thank you very much.

1 ACCEPTED SOLUTION

AshishKM
Kilo Patron
Kilo Patron

Hi, 

We can achieve this use case with either of following ways ;

  • Write a BR on same catalog item task [ sc_task ] table and closed the Task with difference of 5 minute using some current date/time calculation or using gs.sleep(millisecond);
  • Write another workflow on RITM [ sc_req_item ] for same catalog item [ item ] and check the first task and close after [5minute] once the first task closed the main workflow will create next task.
  • Update your current workflow and add the timer & first task as same level and add run script after timer and run script will close the first task , after run script execution complete the second task will trigger.

I tested the 3rd option and it's working as per your requirement.

Timer TIme = 5 minutes

Run Script Code :

find_real_file.png

 

 

Run Script :

find_real_file.png

 

 

var grTask = new GlideRecord('sc_task');
    grTask.addQuery('request_item',current.sys_id); // request_item is RITM reference column in sc_talk table;
    gs.log('request_item='+current.sys_id);
	grTask.addQuery('active' , true); // check if task is still open
	grTask.query(); //execute the query
	
	// check if result set has some task record
    if(grTask.next()){
		
		grTask.state = '3' ; // 3 is choice value for close complete
		grTask.comments ='Task closed by 5minute timer';
		grTask.update();
		
	}

Please review & test and let us know if this design is working for you. 

 

Thanks,

Ashish

Please mark correct answer and helpful for others if it helps you.


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

4 REPLIES 4

AshishKM
Kilo Patron
Kilo Patron

Hi, 

We can achieve this use case with either of following ways ;

  • Write a BR on same catalog item task [ sc_task ] table and closed the Task with difference of 5 minute using some current date/time calculation or using gs.sleep(millisecond);
  • Write another workflow on RITM [ sc_req_item ] for same catalog item [ item ] and check the first task and close after [5minute] once the first task closed the main workflow will create next task.
  • Update your current workflow and add the timer & first task as same level and add run script after timer and run script will close the first task , after run script execution complete the second task will trigger.

I tested the 3rd option and it's working as per your requirement.

Timer TIme = 5 minutes

Run Script Code :

find_real_file.png

 

 

Run Script :

find_real_file.png

 

 

var grTask = new GlideRecord('sc_task');
    grTask.addQuery('request_item',current.sys_id); // request_item is RITM reference column in sc_talk table;
    gs.log('request_item='+current.sys_id);
	grTask.addQuery('active' , true); // check if task is still open
	grTask.query(); //execute the query
	
	// check if result set has some task record
    if(grTask.next()){
		
		grTask.state = '3' ; // 3 is choice value for close complete
		grTask.comments ='Task closed by 5minute timer';
		grTask.update();
		
	}

Please review & test and let us know if this design is working for you. 

 

Thanks,

Ashish

Please mark correct answer and helpful for others if it helps you.


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

THANK YOU VERY MUCH!!! I tried the option you gave me and it worked !!! thank you from the bottom of my heart, you are my hero!!

Good to know that it works for you, actually I tested the case first before replying. Please mark correct answer for others. Thanks, Ashish

Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

To first option: Never ever use gs.sleep() in your business rules. It is not best practice. It affects whole server, so it can cause performance issues.

If business rule need to be postponed, use scheduled event and trigger a script action with this event.