Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Script to run scheduled report as each user in a group

David Sloan
Giga Guru

I occasionally need to run a report for each user in a user group. Currently I do this in a script include, where I iterate through each user in the group and run a function that creates a record on the sysauto_report table, setting run_as and user_list to the person I am running the report for and setting run_type to once. This accomplishes what I need, but since I am doing this weekly, it is cluttering up the Scheduled Reports table, and I wonder if there is a cleaner way to do this. (If you look at my app in Studio, I see hundreds of records under "Scheduled Email of Reports" because it keeps creating Run Once records.)

 

I suppose one possibility is that I instead create this records to run weekly, and my script checks to see if one already exists for that user and that report before creating a new record. Another possibility is that instead of having a script include that is called by a weekly scheduled job, I have a business rule that only runs when a member is added or removed from that group that will add/deactivate the scheduled report for that person. But I wonder if there is a third way that I'm not thinking of that would be better than either of these plans. Anyone have any ideas?

 

2 REPLIES 2

AshishKM
Kilo Patron
Kilo Patron

Hi @David Sloan

Are you not using group configuration for sending scheduled report. You can configure users, group and email for sending report.

 

AshishKMishra_0-1701096092407.png

 

-Thanks,

AshishKMishra

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hi, @AshishKM. It's not just that I need to send the report to everyone in the group. I need to run the report as each person in the group. The report has a filter condition that is dynamic, so the report will produce different results for each user in the group. In other words, I need to run the report as User 1 and send it to them, run it as User 2 and send it to them, and so on. Each run will look different than the previous.