
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2017 03:11 AM
Hi Guys,
I need to send the Pending UAT remainder mail after every 3 days if the change request is not updated.
I have created a schedule job which is running daily.
This job is running only on weekdays as i have checked the conditional checkbox on the job.
The script for the schedule job is
var when = new GlideDateTime();
var delay = new GlideTime();
delay.setValue("72:00:00");
when.add(delay); //passing this value in the eventQueueScheduled() function
var ps = 3;
var pn = parseInt(ps);
if(pn > 0){
var gr = new GlideRecord('change_request');
gr.addEncodedQuery('state=-5^priority=1');
gr.addQuery('sys_updated_on','<',gs.daysAgoStart(pn)); //not updated in 3 days
gr.query();
while(gr.next())
{
gs.eventQueueScheduled('change_request.inactivity',gr,gs.getUserID(),gs.getUserName(),when);
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
}
}
There is an email which is triggered from the event name.
I need this email should be sent after every 3 days, but this is sending email everyday.
Any thoughts on this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 10:51 PM
Hi All,
I achieved this requirement by creating a field Count on the change request form.
The idea was to update the counter by 1 every time the job is running, in my case it is running daily so it will update the counter by 1 every day.
SInce I want to send email after every 3 days which meant on every 4th day, i applied a modulus operator to check the counter is divisible by 4.
In doing this i achieved my requirement of sending email after every 3 days without updating the Updated By and Updated fields.
Here is the schedule job which i wrote :
Since the job is to be run only on weekdays, i have checked the conditonal box and scheduled it for weekdays
Condition:
//Return 'true' to run the job
var answer = false;
//Get the day of week. 1=Monday, 7=Sunday
var now = new GlideDateTime();
//Run only on weekdays
if(now.getDayOfWeek() < 6){
answer = true;
}
answer;
Run this Script:
var gr = new GlideRecord('change_request');
gr.addEncodedQuery('state=-5^priority=1');
gr.addQuery('sys_updated_on','<',gs.daysAgoStart(3));
gr.query();
while(gr.next())
{
var ct = gr.getValue('u_count'); // counter field created with default value 0
if(ct % 4 ==0) // since the email is to be sent after every 3 days
{
gs.eventQueueScheduled('change_request.inactivity',gr,gs.getUserID(),gs.getUserName());
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
}
ct++; // counter will be updated each time the job is run which is daily
gr.setValue('u_count',ct); // capture the value of the updated counter
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
}
I hope someone finds this helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 04:09 AM
HI Kalai,
I have my scheduled job which is running on daily basis and there is a condition on the current record not being updated for 3 days. Since i am using the autoSysField() function the updated date is not getting updated and it stays the same every time the job runs i.e it is running daily. This is the reason that the email is being sent daily. The code which you gave is giving the same output as the code which i have written, but since the job is scheduled to ro run daily it is triggering the email daily instead of sending it on the scheduled date.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 10:51 PM
Hi All,
I achieved this requirement by creating a field Count on the change request form.
The idea was to update the counter by 1 every time the job is running, in my case it is running daily so it will update the counter by 1 every day.
SInce I want to send email after every 3 days which meant on every 4th day, i applied a modulus operator to check the counter is divisible by 4.
In doing this i achieved my requirement of sending email after every 3 days without updating the Updated By and Updated fields.
Here is the schedule job which i wrote :
Since the job is to be run only on weekdays, i have checked the conditonal box and scheduled it for weekdays
Condition:
//Return 'true' to run the job
var answer = false;
//Get the day of week. 1=Monday, 7=Sunday
var now = new GlideDateTime();
//Run only on weekdays
if(now.getDayOfWeek() < 6){
answer = true;
}
answer;
Run this Script:
var gr = new GlideRecord('change_request');
gr.addEncodedQuery('state=-5^priority=1');
gr.addQuery('sys_updated_on','<',gs.daysAgoStart(3));
gr.query();
while(gr.next())
{
var ct = gr.getValue('u_count'); // counter field created with default value 0
if(ct % 4 ==0) // since the email is to be sent after every 3 days
{
gs.eventQueueScheduled('change_request.inactivity',gr,gs.getUserID(),gs.getUserName());
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
}
ct++; // counter will be updated each time the job is run which is daily
gr.setValue('u_count',ct); // capture the value of the updated counter
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
}
I hope someone finds this helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 09:37 AM
Hi Akash,
I have similar requirement can you please explain this line in your code
gr.addQuery('sys_updated_on','<',gs.daysAgoStart(3));
Thanks,
Prachi