- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 05:19 AM
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');
}
}
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 05:58 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 05:36 AM
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();
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 07:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 05:43 AM
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.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 05:46 AM - edited 10-20-2022 05:47 AM
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.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023