Email list of records to users dynamically

John Reynolds
Mega Expert

I'm looking for the best way to create a daily email notification that gets sent out to a dynamic list of users.   The requirements are as follows:

  • Once per day generate a list of records matching the below criteria and email it to each person pulled from the Assigned to field:
    • Record opened today
    • Asset tag field is empty
    • Assigned to (is dynamic, me)
    • Group by   field (u_car_number)
  • Email a link directly to the list of records to the user in the Assigned To field
  • In the email, display the records in text form to the user (glide query)

I've created a filter on the table that I'd like to use as the direct link in the email using the criteria from the 1st bullet: https://<instance-name>.service-now.com/alm_asset_list.do?sysparm_query=assigned_toDYNAMIC90d1921e5f...

Query used: assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe^sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)^asset_tagISEMPTY

I've written most of the Glide Record query I want to include in the email.

The two issues I'm running into / unsure how to accomplish are:

  1. Sending the email once per day to the users
  2. Including only those users in the GlideRecord lookup.

Any help would be appreciated it!

gs.print("Assets pending certification");

var gr = new GlideRecord("alm_asset");

gr.addQuery("state", "Pending");

gr.addQuery("u_asset_tag", "");

gr.oderBy("assigned_to");

gr.orderByDesc('u_car_number');

gr.query();

while(gr.next()) {

gs.print(gr.u_number + " From CAR: " + gr.u_car_number + " Assigned To: " + gr.assigned_to.getDisplayValue());

}

12 REPLIES 12

True, I missed that.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Thanks Alikutty.



I've done the following:


  • Created a new event, asset.tag.needed on the alm_asset table
  • Created a notification that sends when asset.tag.needed is fired on the alm_asset table
  • Created a Scheduled Script Job that runs on demand using the following script:


var gr = new GlideRecord("alm_asset");


gr.addEncodedQuery("assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe^asset_tagISEMPTY"); //Updated to remove date condition and query empty tags


gr.query();


while(gr.next()) {


  gs.eventQueue('asset.tag.needed', gr, gr.assigned_to, '');


}





However, I'm not seeing any indication it is working. No emails are being queued.


Hi John,



In the email notification, have you selected event param 1 contains recipient? Also please check Event logs once to confirm it is triggered.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Hi Alikutty,



Event param 1 / 2 are both select on the notification as well as the "send to event creator" checkbox. The notification is active.   Event logs show the event being triggered only if I test it as a background script.   It does not show in the event log when running "Execute Now" from the Scheduled Script page.


Hi,



Are the notifications triggered when you run the script from background as expected? Also how many records does your query return?



Thanks



Please Hit like, Helpful or Correct depending on the impact of the response