- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 10:47 PM
Hi All,
Actually, I need to send an email notification to the 'assign to' user managers on incident form if the incident state is in progress at every Monday. For this, I have used run script scheduled job in the script I have mentioned the below code. Please help me on this.
In the array I am getting repeated email ID's of managers need to remove that, one email is enough to one particular manager. But by using the below code manager receiving emails repeatedly from all incidents. Please help me on this.
Scheduled script:
var emailList = [];
var incGr = new GlideRecord('incident');
incGr.addQuery('state','3');
incGr.query();
while(incGr.next()){
var userGr = new GlideRecord ('sys_user');
userGr.addQuery('sys_id', incGr.assign_to);
userGr.query();
if(userGr.next()){
var managerEmail = userGr.manager.email;
emailList.push(managerEmail);
gs.event('user_manager_emails', incGr, emailList);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 07:41 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 12:05 AM - edited 10-27-2023 12:06 AM
Hello @Aditya253 ,
Please add this "if" condition after the declaration of variable managerEmail:
if (emailList.toString().indexOf(managerEmail) == -1) {
emailList.push(managerEmail);
}
@Aditya253, Please mark my answer as "Accept as Solution" and "Helpfuls." If it works for you.
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 07:41 AM
Thanks you Khushboo

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 12:20 AM - edited 10-27-2023 12:22 AM
Hello. There are multiple things to be corrected in your script, starting from the fact that InProgress state OOTB has a value of 2, not 3.
Take a look at the script below.
NB. I do not know how your email notification is set up. I assume that you want to send One notification with multiple recipients (the ones from the 'emailList' array). If this is not the case and you want to fire a separate event for any incident, then you need to rethink the whole thing.
var emailList = [];
var arrayUtil = new ArrayUtil();
var incGr = new GlideRecord('incident');
incGr.addNotNullQuery('assigned_to');
incGr.addQuery('state','2');
incGr.query();
while(incGr.next()){
var managerGr = incGr.assigned_to.manager;
if(managerGr && managerGr.email){
if(!arrayUtil.contains(emailList, managerGr.email)){
emailList.push(managerGr.email);
}
}
}
gs.event('user_manager_emails', incGr, emailList);
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 06:14 AM
@Aditya253 if my guidance has helped you resolve your issue, consider makring it Correct. Thanks!
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024