Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Send a Scheduled Email Notification to Assigned to users of HR Case

Uttam Sai
Tera Expert

Hi All,

 

We have a requirement where we need to send a one time email notification to all assigned to users of Active HR case.
This should be done at 12:00 am informing about some new Portal feature we added.
It can be one email for every one or each email to an individual.

Could you please help me how to achieve this


Thank you 
Uttam Sai S

1 ACCEPTED SOLUTION

Rajdeep Ganguly
Mega Guru


Sure, you can achieve this by creating a scheduled job in ServiceNow that will run at 12:00 am and send an email notification to all assigned users of active HR cases. Here are the steps:

1. Create an Email Notification:
- Navigate to System Notification > Email > Notifications.
- Click on New to create a new notification.
- Fill in the necessary details like Name, User, etc.
- In the "Send to" field, select "Specific Users".
- In the "Specific User" field, you will later dynamically add the users.
- In the "Message HTML" field, add the content you want to send in the email.
- Save the notification.

2. Create a Scheduled Script Execution (Scheduled Job):
- Navigate to System Definition > Scheduled Jobs.
- Click on New to create a new scheduled job.
- Fill in the necessary details like Name, Run, etc.
- In the "Script" field, you will write a script to fetch all the active HR cases and the assigned users.

Here is a sample script:

javascript
var gr = new GlideRecord('sn_hr_core_case');
gr.addQuery('state', 'active');
gr.query();
while(gr.next()) {
var userID = gr.assigned_to;
gs.eventQueue('custom.event', gr, userID);
}


In the above script, 'sn_hr_core_case' is the table name for HR cases, 'state' is the field name for the state of the case, 'active' is the state of the case, 'assigned_to' is the field name for the assigned user, and 'custom.event' is the event name that will trigger the email notification.

3. Update the Email Notification:
- Navigate to System Notification > Email > Notifications.
- Open the previously created notification.
- In the "When to send" field, select "Event is fired".
- In the "Event name" field, add the event name 'custom.event'.
- Save the notification.

4. Test the Scheduled Job:
- Navigate to System Definition > Scheduled Jobs.
- Open the previously created scheduled job.
- Click on "Execute Now" to test the job.

Please replace the table names, field names, and event name with the actual ones used in your instance.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER

View solution in original post

6 REPLIES 6

Anil Lande
Kilo Patron

Hi,

Please check below link and try something from your end.

Let us know if you get stuck.

https://www.servicenow.com/community/spm-forum/creating-a-scheduled-notification/m-p/991896

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Anand Kumar P
Giga Patron

Hi @Uttam Sai ,

Refer below link
https://www.servicenow.com/community/developer-forum/creating-schedule-job-to-send-notification/m-p/... 

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

Rajdeep Ganguly
Mega Guru


Sure, you can achieve this by creating a scheduled job in ServiceNow that will run at 12:00 am and send an email notification to all assigned users of active HR cases. Here are the steps:

1. Create an Email Notification:
- Navigate to System Notification > Email > Notifications.
- Click on New to create a new notification.
- Fill in the necessary details like Name, User, etc.
- In the "Send to" field, select "Specific Users".
- In the "Specific User" field, you will later dynamically add the users.
- In the "Message HTML" field, add the content you want to send in the email.
- Save the notification.

2. Create a Scheduled Script Execution (Scheduled Job):
- Navigate to System Definition > Scheduled Jobs.
- Click on New to create a new scheduled job.
- Fill in the necessary details like Name, Run, etc.
- In the "Script" field, you will write a script to fetch all the active HR cases and the assigned users.

Here is a sample script:

javascript
var gr = new GlideRecord('sn_hr_core_case');
gr.addQuery('state', 'active');
gr.query();
while(gr.next()) {
var userID = gr.assigned_to;
gs.eventQueue('custom.event', gr, userID);
}


In the above script, 'sn_hr_core_case' is the table name for HR cases, 'state' is the field name for the state of the case, 'active' is the state of the case, 'assigned_to' is the field name for the assigned user, and 'custom.event' is the event name that will trigger the email notification.

3. Update the Email Notification:
- Navigate to System Notification > Email > Notifications.
- Open the previously created notification.
- In the "When to send" field, select "Event is fired".
- In the "Event name" field, add the event name 'custom.event'.
- Save the notification.

4. Test the Scheduled Job:
- Navigate to System Definition > Scheduled Jobs.
- Open the previously created scheduled job.
- Click on "Execute Now" to test the job.

Please replace the table names, field names, and event name with the actual ones used in your instance.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER

Hi @Rajdeep Ganguly and @sumanta pal ,

There is no Specific user filed , can i use any other field.

 

UttamSai_0-1706291423358.png