How to send reminder after 14 days if task is open

Dasari Srihari
Tera Contributor

Hi All,

 

I need to send notification for opened Catalog Tasks after 14days only one time. I have created variable called reminder(Checkbox variable) after 14days we need set this value true same time we need to send notification,

 

i need to send notification to assignment group, 

 

Please find my script below:

 

var task = new GlideRecord("sc_task");
task.addEncodedQuery('request_item.cat_item=36db14d8db7043005eb551b0cf96196a^stateIN-5,1,2');
task.query();

while (task.next())
{
var text = task.request_item.variables.reminder;

if(text == ' '){

task.text = true;
task.update();
//gs.eventQueue('Test');
}


}


 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Dasari Srihari 

why not use Flow designer for this with no script?

1) Flow triggers every day and checks which sc_task is opened from last 14 days

2) for each of that sc_task send email and update the variable

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Aman Kumar S
Kilo Patron

You can try with below code:

 

var scTask = new GlideRecord("sc_task");
scTask.addEncodedQuery("sys_created_onRELATIVEGT@dayofweek@ago@14^request_item.cat_item=36db14d8db7043005eb551b0cf96196a^stateIN-5,1,2^u_reminder=false");
scTask.query();
while(scTask.next()){
gs.eventQueue('event name', object, parm1,parm2);// pass correct variables
scTask.u_reminder = true;
scTask.update();
}

Best Regards
Aman Kumar

Hi @Aman Kumar S ,

 

Variable available only in RITM table not available in Task table

johnfeist
Mega Sage
Mega Sage

Hi Dasari,

 

You have a couple of options.

 

The first option is to have a job that runs daily (or more frequently).  In that job you will query for all open task records for the given item like you are currently showing.  You need to add two conditions:

  • created_on before 14 days ago.  For this you'll need to grab a glide datetime and subtract 14 days from it to get the date you need.
  • reminder == ""

Next, create an event for this and set up your notification to be triggered by this event.  From there, you loop through the data and can have the notifications sent by firing the event (eventQueue()).  The final step in your loop is setting the reminder field to true. 

 

The second option is to adjust your flow/workflow so that when the task is assigned a timer is started for 14 days.  You have the task set to wait for completion so that the task will go to both the timer and the next step in your process which should be a decision between did the task complete or did the timer expire.  From there just set your flow accordingly.

 

You might consider changing your reminder field to a date or datetime field.  That way when people complain about not getting what they requested, you have more specific data about when the reminder was sent.

 

 

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Dasari Srihari 

 

You can create a Scheduled Job which will run Daily to check if any Catalog task which was created 14 days back is still open. Please find sample code below:

 

 

var tsk = new GlideRecord("sc_task");
tsk.addEncodedQuery("sys_created_onRELATIVELT@dayofweek@ahead@14^sys_created_onRELATIVEGT@dayofweek@ago@14^request_item.cat_item=36db14d8db7043005eb551b0cf96196a^stateIN-5,1,2");
tsk.query();

while (tsk.next())
{
var text = tsk.request_item.variables.reminder;

if(text == ' '){
tsk.text = true;
tsk.update();
gs.eventQueue('<event name>',tsk,param1,param2);
}


}

 

 

You can change Query from 14 days to 13 or 15 based on what it suits for your requirement.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023