I am new to servicenow want to know how to schedule jobs using glide script . Please explain steps with detailed

Shilpi Sharma2
Tera Contributor

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.

1 ACCEPTED SOLUTION

Hi Shilpi,

PFB the steps:

1) Register and event through Event Registry.

find_real_file.png

2) Configure Notification as below

find_real_file.png

find_real_file.png

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).

find_real_file.png

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

View solution in original post

14 REPLIES 14

Hi Shilpi,

Any update on this?

 

Regards,

Monika

I create a schedule job as mention in your post but it is not working don't know why.

I am using Jakarta version and my table name is "incident".

I am using Jakarta version and my table name is "incident".

Are you working on OOTB incident table?

Have you also configured event and notification?

If yes then please provide me the screenshot of what you have configured.

 

Regards,

Monika

Yes i am working on OOTB incident table.

 

Please find attachment with their names specified

Event Regstry

find_real_file.png

Schedule Job

find_real_file.png

Notification Images

find_real_file.pngfind_real_file.pngfind_real_file.pngfind_real_file.png