- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2023 09:22 AM - edited ‎09-18-2023 09:24 AM
I want to be able to run a report when a user raises a service request. It will be an extract of some data and emailed to them.
To achieve this my plan is to create a Flow with Flow Designer and have that execute when the request is raised.
To facilitate the executing of the script I've created a new Action with the following code:
(function execute(inputs, outputs) {
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
var random = Math.floor(Math.random()*90000) + 10000;
scheduled_report.name = 'AutoReport - ' + random;
//Run report as given user to show only his records
scheduled_report.run_as = 'xxxxxx891bc105105915848cd34bcbbd'; //gs.getUser();
//Sent report to same user, so he receives his own report
scheduled_report.user_list = 'xxxxxx891bc105105915848cd34bcbbd'; //gs.getUser();
//Only send the report once
//It will be rescheduled if needed
scheduled_report.run_type = 'once';
scheduled_report.report_title = 'AutoReport';
scheduled_report.report = inputs.report_sys_id;
scheduled_report.omit_if_no_records = 'false';
scheduled_report.output_type = 'XLSX';
scheduled_report.page_size = 'A4';
//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();
})(inputs, outputs);
The code actually works. A scheduled report is created and executed. However despite setting the output type to XLSX I'm getting both an XLSX and a PDF attached to the email that is sent.
Can anyone tell me why? And how to fix it? I've been able to find anyone with a similar problem!
(I had been looking at some previous work about On Demand reports that @Chris Fulton had talked about but that doesn't appear to be available anymore).
Many thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2023 01:28 AM - edited ‎09-19-2023 01:29 AM
I've solved the issue. While I'd looked at the content of the PDF, I hadn't realised it's significance. It said:
"Access to this content denied based on report_view ACLs."
A bit of browsing and a light blub moment later, I added an ACL that allowed the user running the report to read the report_view of the table in question.
PDF disappeared and I got the one attachment I was expecting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2023 10:30 AM
Spike,
Here is the code I used when I wrote the "on-demand" reports. I don't believe it's going to be much help for what you are seeing though. I haven't done much scripting with reports in a long while and don't have an answer as to why it's giving you both PDF and XLS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2023 01:07 AM
Thanks for this. I was wondering how to trigger the report but leave it inactive. This has helped there.
You're right though, still doesn't help me with the two attachments. And it still happens using your trigger code, rather than mine.
Interestingly, even once the row is inserted into sysauto_reports, if I manually execute it, it still gets two attachments. Got to be something in how the record is held but I can't see anything on the table or in the log to indicate why.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2023 01:28 AM - edited ‎09-19-2023 01:29 AM
I've solved the issue. While I'd looked at the content of the PDF, I hadn't realised it's significance. It said:
"Access to this content denied based on report_view ACLs."
A bit of browsing and a light blub moment later, I added an ACL that allowed the user running the report to read the report_view of the table in question.
PDF disappeared and I got the one attachment I was expecting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2023 05:27 AM
Spike,
I'm glad to hear you were able to resolve the issue. Sometimes it's the little things we overlook - I do it as well. I wouldn't have thought to look there for an error message either but I'm glad you did.