- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2017 07:23 AM
I have many Scheduled Reports setup; some more complex than others but have hit a snag with scripting conditions so that it only emails the report out to named individuals in the report.
I tried referencing the script from the post here; HELP! How to dynamically set recipients of an existing Scheduled Report to email addresses that are ... but had trouble using this in my report.
This particular report is simple in that it it populates 'x' amount of data grouped by the "Assigned to" on all currently active tickets
My report is defined as......
Instead of the report emailing a distribution list in the "Email Address" field, i just want it to email the contacts that appear in "assigned to" list who do already have an email address attached to their "contact card" in Service Now. I believe a script will achieve this but have no experience writing script.
Any help would be greatly appreciated.
Solved! Go to Solution.
- 4,463 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2017 03:17 PM
Welcome to the community, James!
After creating your report, pull down the menu and choose "Schedule". Note that you'll want to omit the "Assigned to" query parameter.. we'll take care of that later in our script:
Then on the resulting page, click the "Conditional" box, and a script area shows up. Taking the suggested script from the other thread you referenced, paste it in the script area:
Here's the script that should work for you:
answer = lookupUsersAndUpdateReport();
function lookupUsersAndUpdateReport(){
// look up "assigned_to" people -- assumes "table" is task-based
var senderArray = [];
var taskQueryGR = new GlideRecord(current.report.table);
taskQueryGR.addEncodedQuery(current.report.filter);
taskQueryGR.query();
while (taskQueryGR.next()){
senderArray.push(taskQueryGR.assigned_to + '');
}
current.user_list = senderArray.join(',');
current.setWorkflow(false);
current.update();
current.setWorkflow(true);
// only return true if there were records listed in the result set
if (senderArray.length > 0){
return true;
}
return false;
}
..And that should do it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2017 03:17 PM
Welcome to the community, James!
After creating your report, pull down the menu and choose "Schedule". Note that you'll want to omit the "Assigned to" query parameter.. we'll take care of that later in our script:
Then on the resulting page, click the "Conditional" box, and a script area shows up. Taking the suggested script from the other thread you referenced, paste it in the script area:
Here's the script that should work for you:
answer = lookupUsersAndUpdateReport();
function lookupUsersAndUpdateReport(){
// look up "assigned_to" people -- assumes "table" is task-based
var senderArray = [];
var taskQueryGR = new GlideRecord(current.report.table);
taskQueryGR.addEncodedQuery(current.report.filter);
taskQueryGR.query();
while (taskQueryGR.next()){
senderArray.push(taskQueryGR.assigned_to + '');
}
current.user_list = senderArray.join(',');
current.setWorkflow(false);
current.update();
current.setWorkflow(true);
// only return true if there were records listed in the result set
if (senderArray.length > 0){
return true;
}
return false;
}
..And that should do it!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2020 02:08 PM
Thank you so much Valor! I confirm that this still works now, 3 years later.
I noticed that in your script, if a user is assigned to 3 tasks in the report results, he gets added to the list of users 3 times. That means there's 2 duplicate entries for the user. I'm also unsure of what the impact of trying to set blank users are, which may happen if it processes a task that has a blank assigned_to.
Here is the way I fixed this duplication and avoided tasks with a blank assigned_to.
answer = lookupUsersAndUpdateReport();
function lookupUsersAndUpdateReport(){
// look up "assigned_to" people -- assumes "table" is task-based
var senderArray = [];
var PrevSender = '';
var taskQueryGR = new GlideRecord(current.report.table);
taskQueryGR.addEncodedQuery(current.report.filter);
taskQueryGR.addEncodedQuery('assigned_toISNOTEMPTY');
taskQueryGR.orderBy('assigned_to');
taskQueryGR.query();
while (taskQueryGR.next()){
if (PrevSender != taskQueryGR.assigned_to + ''){ //filters out duplicate assignees
senderArray.push(taskQueryGR.assigned_to + '');
PrevSender = taskQueryGR.assigned_to + '';
}
}
current.user_list = senderArray.join(',');
current.setWorkflow(false);
current.update();
current.setWorkflow(true);
// only return true if there were records listed in the result set
if (senderArray.length > 0){
return true;
}
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2023 08:34 AM
Hi @Valor1, @ how are you?!
Could you please give me a suggestion?!
I have a Report needs to be sent to the Group Holder, but this Holder is in a Reference field called "Business Partner Department" (PRINT_1),
I checked and suggested that I created a "Dot Walk" in the "Condition" section of the Schedule (PRINT_2), but unfortunately is not working:
I just need to get the "Holder" of a reference field for the Report to be sent.
Could anyone please give me a tip or script suggestion?
Thanks for the support!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 01:54 AM
thanks very much...working great now!