- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2018 03:01 AM
I am new to servicenow want to know how to schedule jobs using glide script . Please explain steps with detailed.
My requirement is that i need to trigger a mail before the expiry date to end user. before 15/10/05 days.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2018 02:36 AM
Hi Shilpi,
PFB the steps:
1) Register and event through Event Registry.
2) Configure Notification as below
3) Create a Scheduled job from System definition->Scheduled Job.
4) Select Automatically run a script of your choosing.
5) Create a job with run field as daily and select a particular time on which this job will trigger.(I have selected on demand for test purpose).
6) Write below script under Run this script.
var gr = new GlideRecord('x_197397_test_appl_test123');// give your table name
gr.query();
while (gr.next())
{
//gs.info("expiry date :"+exp);
var dt = new GlideDateTime().getDate();
var dt1 = new GlideDateTime(exp).getDate();
var diff = GlideDateTime.subtract(dt,dt1);
var a = diff.getDisplayValue();
var arr=a.split(" ");
var day =arr[0];
if(day == 15)
{
gs.eventQueue('x_197397_test_appl.Reminder for expiry',gr,gr.caller,gs.getUserID());// give your event name in first parameter and pass the parameter 3rd and 4th as per your requirement
}
else if(day == 10)
{
gs.eventQueue('x_197397_test_appl.Reminder for expiry',gr,gr.caller,gs.getUserID());
}
else if(day == 5)
{
gs.eventQueue('x_197397_test_appl.Reminder for expiry',gr,gr.caller,gs.getUserID());
}
}
Hope this helps.
Regards,
Monika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2018 03:36 AM
Hi,
1. Create an Event Registry for a table let's call it incident in System Policy Menu and call the event name my.expire.event.
2. Create a Notification from System Notification menu as follow, make sure the event name is just created one.
3. Define Scheduled Job from System Definition menu to fire the event as follows.
Hope it helps
Regards
Yusuf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2018 04:01 AM
Hi Shilpi,
Please let me know if the expiry date is a Datetime type or a Date type field?
Do you want to configure the same for scoped application?
Regards,
Monika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2018 04:07 AM
Hi Monika,
Yes it is dateTime field . Yes i want to configure it for SCOED application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2018 02:36 AM
Hi Shilpi,
PFB the steps:
1) Register and event through Event Registry.
2) Configure Notification as below
3) Create a Scheduled job from System definition->Scheduled Job.
4) Select Automatically run a script of your choosing.
5) Create a job with run field as daily and select a particular time on which this job will trigger.(I have selected on demand for test purpose).
6) Write below script under Run this script.
var gr = new GlideRecord('x_197397_test_appl_test123');// give your table name
gr.query();
while (gr.next())
{
//gs.info("expiry date :"+exp);
var dt = new GlideDateTime().getDate();
var dt1 = new GlideDateTime(exp).getDate();
var diff = GlideDateTime.subtract(dt,dt1);
var a = diff.getDisplayValue();
var arr=a.split(" ");
var day =arr[0];
if(day == 15)
{
gs.eventQueue('x_197397_test_appl.Reminder for expiry',gr,gr.caller,gs.getUserID());// give your event name in first parameter and pass the parameter 3rd and 4th as per your requirement
}
else if(day == 10)
{
gs.eventQueue('x_197397_test_appl.Reminder for expiry',gr,gr.caller,gs.getUserID());
}
else if(day == 5)
{
gs.eventQueue('x_197397_test_appl.Reminder for expiry',gr,gr.caller,gs.getUserID());
}
}
Hope this helps.
Regards,
Monika