Need to add one condition to Scheduled Job

Ankita NA
Tera Contributor

I have created one notification which will trigger when the application present in application table will have a target decommission date (TDD) exactly one month prior to today (means if my application TDD is 4/21/2023 then notification should trigger on   3/21/2023). I have to write the condition in scheduled job . Please help how it can be achieved using scheduled job.

 

 
2 ACCEPTED SOLUTIONS

AnveshKumar M
Tera Sage
Tera Sage

Hi @Ankita NA ,

You can use the RELATIVE query to get the CIs, follow below article to achieve your requirement.

 

1. Register an Event:

Create an event in Event registry like the one below.

AnveshKumarM_0-1679387183207.png

 

2. Scheduled Job:

Create a scheduled job like the one below, and use the script to fetch TDD in 30 days from now.

AnveshKumarM_1-1679387256140.png

 

AnveshKumarM_2-1679387268738.png

 

 

 

 

var appGr = new GlideRecord('cmdb_ci_appl');
//Change field name to the one you are using in your form, mine is u_target_decommission
appGr.addEncodedQuery('u_target_decommissionRELATIVEGT@dayofweek@ahead@30');
appGr.query();
while(appGr.next()){
	gs.eventQueue('app.decom.notify', appGr);
}

 

 

 

Note: I'm assuming target decommission date field as u_target_decommission in encoded query, you should change it to the one as you defined in your table.

 

3. Create Notification:

Create a notification like the one below.

AnveshKumarM_6-1679388214020.png

 

Specify who should receive,

AnveshKumarM_4-1679387728269.png

 

Define the mail content,

AnveshKumarM_5-1679387756348.png

 

Thanks,

Anvesh

Thanks,
Anvesh

View solution in original post

OlaN
Giga Sage
Giga Sage

Hi,

This could also be done with a Flow, and would require no scripting.

Simple example below:

flow-send-notifications-daily.png

View solution in original post

3 REPLIES 3

Ratnakar7
Mega Sage
Mega Sage

Hi @Ankita NA ,

 

you can follow these steps:

  1. Navigate to the Scheduled Job list by typing "Scheduled Jobs" in the navigation bar.

  2. Find the Scheduled Job that you want to add a condition to and click on it to open its record.

  3. In the "Condition" field, you can use the ServiceNow GlideDate() function to check if the target decommission date (TDD) is exactly one month prior to today. Here is an example condition that you can use:

application_table.target_decommission_date.getGlideObject().getNumericValue() = gs.monthsAgoStart(1).getNumericValue()

This condition checks if the TDD in the application_table is equal to the start of the month that is one month ago from today. If this condition is true, then the notification will trigger

     

     4. Click on "Save" to save your changes to the Scheduled Job.

 

If my response helps you to resolve the issue close the question by Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.

 

Thanks,

Ratnakar

AnveshKumar M
Tera Sage
Tera Sage

Hi @Ankita NA ,

You can use the RELATIVE query to get the CIs, follow below article to achieve your requirement.

 

1. Register an Event:

Create an event in Event registry like the one below.

AnveshKumarM_0-1679387183207.png

 

2. Scheduled Job:

Create a scheduled job like the one below, and use the script to fetch TDD in 30 days from now.

AnveshKumarM_1-1679387256140.png

 

AnveshKumarM_2-1679387268738.png

 

 

 

 

var appGr = new GlideRecord('cmdb_ci_appl');
//Change field name to the one you are using in your form, mine is u_target_decommission
appGr.addEncodedQuery('u_target_decommissionRELATIVEGT@dayofweek@ahead@30');
appGr.query();
while(appGr.next()){
	gs.eventQueue('app.decom.notify', appGr);
}

 

 

 

Note: I'm assuming target decommission date field as u_target_decommission in encoded query, you should change it to the one as you defined in your table.

 

3. Create Notification:

Create a notification like the one below.

AnveshKumarM_6-1679388214020.png

 

Specify who should receive,

AnveshKumarM_4-1679387728269.png

 

Define the mail content,

AnveshKumarM_5-1679387756348.png

 

Thanks,

Anvesh

Thanks,
Anvesh

OlaN
Giga Sage
Giga Sage

Hi,

This could also be done with a Flow, and would require no scripting.

Simple example below:

flow-send-notifications-daily.png