- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 01:10 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 01:41 AM - edited 03-21-2023 01:45 AM
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.
2. Scheduled Job:
Create a scheduled job like the one below, and use the script to fetch TDD in 30 days from now.
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.
Specify who should receive,
Define the mail content,
Thanks,
Anvesh
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 01:50 AM
Hi,
This could also be done with a Flow, and would require no scripting.
Simple example below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 01:28 AM - edited 03-21-2023 01:33 AM
Hi @Ankita NA ,
you can follow these steps:
Navigate to the Scheduled Job list by typing "Scheduled Jobs" in the navigation bar.
Find the Scheduled Job that you want to add a condition to and click on it to open its record.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 01:41 AM - edited 03-21-2023 01:45 AM
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.
2. Scheduled Job:
Create a scheduled job like the one below, and use the script to fetch TDD in 30 days from now.
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.
Specify who should receive,
Define the mail content,
Thanks,
Anvesh
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 01:50 AM
Hi,
This could also be done with a Flow, and would require no scripting.
Simple example below: