Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Trigger email notification for change task

Nilofer1
Giga Expert

Nilofer1_0-1680209871133.png

I have a change task.  If the task is not assigned to any assignee in "assigned to" field till 2 days then I need to trigger a notification and wait for 2 more days and trigger notification again, if the task is still not assigned to anyone. 

How to achieve this?

1 ACCEPTED SOLUTION

Punit S
Giga Guru

Hi Nilofer,

 

To achieve this goal your stated above,  in ServiceNow, you can create a Business Rule with a Scheduled Script.

Here are the steps to create the Business Rule:

  1. Go to the Business Rules application in ServiceNow.
  2. Click on the New button.
  3. Fill in the following details:
    • Name: e.g. "Change Task Assignment Notification"
    • Table: Change Task [change_task]
    • When to run: Before
    • Insert: checked
  4. Under Advanced, check the "Run on Load" checkbox.
  5. Save the Business Rule.

Next, you will need to create a Scheduled Script to run every 2 days to check the "assigned to" field of the Change Task and send out notifications if the task is still unassigned.

Here are the steps to create the Scheduled Script:

  1. Go to the Scheduled Jobs application in ServiceNow.
  2. Click on the New button.
  3. Fill in the following details:
    • Name: e.g. "Check Unassigned Change Tasks"
    • Interval: 2 days
    • Active: checked
    • Run: Script
  4. Under the Script section, copy and paste the following code:
 

 

var changeTaskGr = new GlideRecord('change_task');
changeTaskGr.addQuery('assigned_to', '');
changeTaskGr.addQuery('sys_updated_on', '<=', gs.daysAgo(2));
changeTaskGr.query();

while (changeTaskGr.next()) {
  // send notification for unassigned task
  gs.eventQueue('change.task.unassigned.notification', changeTaskGr, gs.getUserID(), 600);
}

5.Save the Scheduled Script.

 

This script queries all Change Tasks that have not been assigned to anyone and have not been updated for the last 2 days. For each of these tasks, it sends a notification event to a custom event queue named "change.task.unassigned.notification".

You can then create a Notification that listens to the  "change.task.unassigned.notification" event and sends out the desired email or message to the relevant users. You can also create another Scheduled Script to run after another 2 days to repeat the notification process if the task is still unassigned.

 

Please mark my answer correct/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal. 

Thanks,
Punit

 

View solution in original post

1 REPLY 1

Punit S
Giga Guru

Hi Nilofer,

 

To achieve this goal your stated above,  in ServiceNow, you can create a Business Rule with a Scheduled Script.

Here are the steps to create the Business Rule:

  1. Go to the Business Rules application in ServiceNow.
  2. Click on the New button.
  3. Fill in the following details:
    • Name: e.g. "Change Task Assignment Notification"
    • Table: Change Task [change_task]
    • When to run: Before
    • Insert: checked
  4. Under Advanced, check the "Run on Load" checkbox.
  5. Save the Business Rule.

Next, you will need to create a Scheduled Script to run every 2 days to check the "assigned to" field of the Change Task and send out notifications if the task is still unassigned.

Here are the steps to create the Scheduled Script:

  1. Go to the Scheduled Jobs application in ServiceNow.
  2. Click on the New button.
  3. Fill in the following details:
    • Name: e.g. "Check Unassigned Change Tasks"
    • Interval: 2 days
    • Active: checked
    • Run: Script
  4. Under the Script section, copy and paste the following code:
 

 

var changeTaskGr = new GlideRecord('change_task');
changeTaskGr.addQuery('assigned_to', '');
changeTaskGr.addQuery('sys_updated_on', '<=', gs.daysAgo(2));
changeTaskGr.query();

while (changeTaskGr.next()) {
  // send notification for unassigned task
  gs.eventQueue('change.task.unassigned.notification', changeTaskGr, gs.getUserID(), 600);
}

5.Save the Scheduled Script.

 

This script queries all Change Tasks that have not been assigned to anyone and have not been updated for the last 2 days. For each of these tasks, it sends a notification event to a custom event queue named "change.task.unassigned.notification".

You can then create a Notification that listens to the  "change.task.unassigned.notification" event and sends out the desired email or message to the relevant users. You can also create another Scheduled Script to run after another 2 days to repeat the notification process if the task is still unassigned.

 

Please mark my answer correct/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal. 

Thanks,
Punit