- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 12:50 AM
I have a requirement of when state is InProgress for more than 10 days , notification should be triggered.
1st notification to be send after 10 days of State in InProgress
2nd notification to be send after 15 days of State in InProgress
If action taken on state after the 1st notification then 2nd notification should not be triggered.
Please assist me on this.
@Ankur Bawiskar @Community Alums
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 01:29 AM
Hi @Balaji Munusamy ,
You can set up a script that runs periodically, checking records where the state is "InProgress" for more than 10 days. You can do this using Business Rules or Scheduled Jobs in ServiceNow. Here's an outline:
-
Scheduled Job (Background Script):
- Create a script to run as a scheduled job that queries records with the state "InProgress" for more than 10 days.
- For instance, create a scheduled job that runs every day.
- Use GlideRecord queries to find records where the state is "InProgress" and the 'sys_updated_on' field is more than 10 days old.
- When the condition is met, trigger the first notification.
-
1st Notification:
- Once you've identified the records that meet the criteria (10 days in "InProgress"), send the first notification.
- Use the Notification API to trigger the notification when the condition is met.
-
Stop 2nd Notification:
- Keep track of the first notification.
- You could set a field on the record, e.g., "Notified" as 'true', when the first notification is sent.
- When the second notification check is performed (15 days in "InProgress"), verify if "Notified" is 'true'. If so, don't send the notification; otherwise, send it.
Here's a basic example (to be adapted to your environment):
var gr = new GlideRecord('your_table'); // Change 'your_table' to the table name you're working with
gr.addQuery('state', 'InProgress');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(10)); // For 10 days
gr.query();
while (gr.next()) {
// Check if the notification for 10 days hasn't been sent yet
if (!gr.getValue('firstNotificationSent')) {
// Send 1st notification
gs.eventQueue('incident.inProgress10Days', gr, gs.getUserID(), gr.getValue('assigned_to'));
gr.setValue('firstNotificationSent', true); // Mark as sent
gr.update();
}
// Check for 15 days if the 2nd notification needs to be sent
if (!gr.getValue('secondNotificationSent')) {
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(15)); // For 15 days
gr.query();
if (gr.next()) {
// Send 2nd notification
gs.eventQueue('incident.inProgress15Days', gr, gs.getUserID(), gr.getValue('assigned_to'));
gr.setValue('secondNotificationSent', true); // Mark as sent
gr.update();
}
}
}
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 01:29 AM
Hi @Balaji Munusamy ,
You can set up a script that runs periodically, checking records where the state is "InProgress" for more than 10 days. You can do this using Business Rules or Scheduled Jobs in ServiceNow. Here's an outline:
-
Scheduled Job (Background Script):
- Create a script to run as a scheduled job that queries records with the state "InProgress" for more than 10 days.
- For instance, create a scheduled job that runs every day.
- Use GlideRecord queries to find records where the state is "InProgress" and the 'sys_updated_on' field is more than 10 days old.
- When the condition is met, trigger the first notification.
-
1st Notification:
- Once you've identified the records that meet the criteria (10 days in "InProgress"), send the first notification.
- Use the Notification API to trigger the notification when the condition is met.
-
Stop 2nd Notification:
- Keep track of the first notification.
- You could set a field on the record, e.g., "Notified" as 'true', when the first notification is sent.
- When the second notification check is performed (15 days in "InProgress"), verify if "Notified" is 'true'. If so, don't send the notification; otherwise, send it.
Here's a basic example (to be adapted to your environment):
var gr = new GlideRecord('your_table'); // Change 'your_table' to the table name you're working with
gr.addQuery('state', 'InProgress');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(10)); // For 10 days
gr.query();
while (gr.next()) {
// Check if the notification for 10 days hasn't been sent yet
if (!gr.getValue('firstNotificationSent')) {
// Send 1st notification
gs.eventQueue('incident.inProgress10Days', gr, gs.getUserID(), gr.getValue('assigned_to'));
gr.setValue('firstNotificationSent', true); // Mark as sent
gr.update();
}
// Check for 15 days if the 2nd notification needs to be sent
if (!gr.getValue('secondNotificationSent')) {
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(15)); // For 15 days
gr.query();
if (gr.next()) {
// Send 2nd notification
gs.eventQueue('incident.inProgress15Days', gr, gs.getUserID(), gr.getValue('assigned_to'));
gr.setValue('secondNotificationSent', true); // Mark as sent
gr.update();
}
}
}
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 02:51 AM - edited 11-02-2023 02:52 AM
Hi @Ratnakar7 ,
Here 'firstNotificationsent' is True/False type?
I'm using 'u_follow_up1' field as True/false