Scheduled Report to email contacts that are in the report's output

James Rostron1
Tera Expert

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......

snow.png

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.

1 ACCEPTED SOLUTION

Valor1
Giga Guru

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:


find_real_file.png


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:


find_real_file.png



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!


View solution in original post

5 REPLIES 5

raushan
Tera Contributor

I have done the same for incident table but dint get this to work, because i cannot see this in To field on outlook but only can see the users which i have added manually. Will this only work without putting user and group field on scheduled report? please confirm