Can scheduled reports send personal summaries?

peterraeves
Mega Guru

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.

1 ACCEPTED SOLUTION

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.


View solution in original post

27 REPLIES 27

What I did was the following:


1) Create the report you would like to see. It would have the filter '<Assignment Group.manager> <is> <javascript:gs.getUserID();



In best case, you would just have to redirect the managers to this report, so they can see the report directly and it would require no work on your part.


In worst case, they actually want to have the report send to them in email... In this case you will need to do the following:



2) Create the template Scheduled Report you would like to send out. Fill in all the fields (subject, report, content, etc) and put it on 'Demand', so it never runs on its own.


3) Create a scheduled job, which runs periodically. This scheduled job, will loop over all assignment groups and for every assignment group, which has a manager, you would create a copy of the original Scheduled Report (just use the gliderecord.insert functionality), but replace the 'run as' field with the manager and put it on 'Once', so it will run directly when created.



Optional things are:


- Create a cleanup script to remove all 150 scheduled reports, which are created every month


- Modify your script, so it can account for attached reports to the original report



Keep in mind that


- The managers have the appropriate rights to see the incidents. Managers that do not enter SN often, might not even have the correct roles to see the records.


Hi Peter,



Can you help me with these scripts.



We want t end these reports like in excel files.



Kindly provide your input



Regards,


Pratik Kumar


They really are very basic scripts. You should be able to do them. I would so something like the script below.



//Get all groups


var gr = new GlideRecord('sys_user_group');


gr.query();


//Get template


var template = new GlideRecord('sysauto_report');


template.get(<id for template>);



while (gr.next()) {


template.sys_id = '';


template.run_as = gr.manager;


template.run_type = 'once';


template.insert();


}



If the other scripts are too complex for you, they are not really needed. You only need the one above.


Hi



Step 1:I have created one report Name "Inc"


find_real_file.png



Step 2: I have created on schedule report:-


find_real_file.png



Step 3:- I have created one schedule job and paste the code give by you.



Capture.PNG



Still i am not able to achieve this requirement.



Kindly help



Regards,


Pratik Kumar


What happened when you executed that script?