- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2016 05:38 AM
Before I go out scripting, I was wondering if there was a simple way to do the following. I want to send out reports on a regular interval, that contain a summary of the incidents logged by a certain user. Every time the user should receive a pdf with the list containing all incidents he logged from the last time this report was send.
Therefore, we don't know up front who we will be sending to and we don't want to make a scheduled report for every user, and only sending it when it isn't empty. I haven't tried this yet, but I could probably have a script that loops over all assignees for that period of time, that sets up scheduled reports that would run as that user and that would have the list conditioned on "assigned_to = gs.getUserID()", but I was wondering if there was a more OOTB, cleaner way to do this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2016 07:22 AM
I did fix this problem. What you need to do is
1) Create the report to use "dynamic = me". For example "opened by - is dynamic - me"
2) Create a template for the schedule you want to run
3) Create a Scheduled Script that will use the template to create new ScheduleOnce schedules for all users or groups you want. The script will set the "run as" field to the specific user and let the schedule run for that user.
In step 2) I originally used a Script Include to create the schedule:
var scheduled_report = new GlideRecord('sysauto_report');
//Set the scheduled job to active
scheduled_report.active = 'true';
//We add report title and user name to the name for clarity
scheduled_report.name = ''
+ 'Scheduled Email Report of '
+ report.title
+ ' - '
+ user.name;
//Run report as given user to show only his records
scheduled_report.run_as = user.sys_id;
//Sent report to same user, so he receives his own report
scheduled_report.user_list = user.sys_id;
//Only send the report once
//It will be rescheduled if needed
scheduled_report.run_type = 'once';
scheduled_report.report_title = subject;
scheduled_report.report_body = body;
scheduled_report.report = report.sys_id;
scheduled_report.omit_if_no_records = omit;
//Now, insert the newly created scheduled job to start running
//As it is a "once" job, it will run automatically
var answer = scheduled_report.insert();
The function had parameters like "user" and "report", but I just recently discovered that there is an OOTB script include for this functionality. So it might be better to check that one out as well. It's an object called "ScheduleOnce" and is an extension of the "Schedule" object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 05:27 AM
I am not receiving any notification.
And what is found after executing this script lots of duplicate schedule report got created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 05:36 AM
They are not duplicates, because the 'run_as' field should be different every time. You create one report for every manager.
Also, there are no notifications because you did not set the user_list field. It should also be set as the manager.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 05:04 AM
Hello Peter,
I found your article while searching for a method of dynamically sending reports to those users found on a report - in my case, its a report that lists all outstanding RITM approvals, the report should be sent to these people to give them 'the hurry-up'.
So the report was created against the approval table, it can use the Approver is(Dynamic) Me filter.
I created the report schedule template, and I can create a Scheduled Job to run a script - but I struggle to understand how the script can set the schedule Run As user and the Send to User_List fields, so that each user receives a copy of 'their own report' showing a list of their outstanding approvals?
If it cant do this, I apologise for your time lost reading this far 🙂
Thanks
Russ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 06:03 AM
You iterate over the list of users and for every user you create a new 'scheduled report'. The newly created record will have the fields 'run_as' and 'user_list', which you set equal to the sys id of the user of the current iteration (user.sys_id). I have example code in the selected answer (Re: Can scheduled reports send personal summaries? )
In the template you should not set any 'run as' or 'user list'. It will be set in the script. I ended up modifying my script so it will take the values in run as and user list of the template and add it to the user in the iteration. For example, if you want all copies to be sent to a specific person (eg: manager of a team, system admin for debugging, etc). It is really up to you, but the users in the iteration are unknown upfront, so you will only set them in the script through the iteration and not in the template.
Edit: Here is a simpler version of the script, with only the necessary fields (Re: Can scheduled reports send personal summaries? )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 06:12 AM
Oh ok - think i got it now, the script is iterating through the whole user base, and running the report for each one?
Thanks.