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

Running as a BG Script produces 8 event logs.   Those 8 logs appear to reference my 8 records matching the query. It does not create a log for other users in the assigned to field.



The notifications are not being triggered from the BG script.



find_real_file.png



find_real_file.png



find_real_file.png




----



I updated the Scheduled Script to include a little log before the while statement and it is showing in the system logs but the actual event still does not appear to trigger.



gs.log('Assets need tags','run test');


It seems like we have now 2 issues to handle



The first issue is weird, Maybe you should try removing the (function ()) block if you have added it (I do not see this on OOB instance)



Can you share a screen sprint of your notification? I believe you have selected the Send When field to Event is fired.



Thanks


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


On a second thought, Is the scheduled job in a scoped application? The background scripts runs on a global scope and should be able to create event records.



Thanks


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