Schedule report on demand

Dan Belostotsk1
Mega Expert

Hello,
 We need to send a report on demand to its requestor.

 The idea is to have a catalog item requesting a specific report.
 Once the request is submitted we can use the dedicated schedule job created for that report and run:SncTriggerSynchronizer.executeNow(job_sys_id);

 My question, how can we set the report email recipients dynamically to its requestor only?
 Any other option apart from publishing a report with a dedicated URL where we'll be able to provide the data on demand? 

 

 Thank you.

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Hey Dan,

If the report is only going to be used for this process. You could set the user_list to the sys_id of the requester only and save the record before triggering the report.

The below is just me testing in a background script with the variable sysid being the report in question and passing my logged in userID as the recepient, for your use case you'd use

current.request.requested_for.sys_id.

var sysid = 'f98c7b992f859c5049375fd92799b615';
var user1 = gs.getUserID();

var report = new GlideRecord('sysauto_report');
report.get('sys_id',sysid);

report.user_list = user1 + '';
report.update();

SncTriggerSynchronizer.executeNow(sysid);

Hope that makes sense? If you need the example inside a workflow do let me know

 

If my reply helped with your issue please mark helpful 👍 and correct if your issue is now resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having.

View solution in original post

4 REPLIES 4

Kieran Anson
Kilo Patron

Hey Dan,

If the report is only going to be used for this process. You could set the user_list to the sys_id of the requester only and save the record before triggering the report.

The below is just me testing in a background script with the variable sysid being the report in question and passing my logged in userID as the recepient, for your use case you'd use

current.request.requested_for.sys_id.

var sysid = 'f98c7b992f859c5049375fd92799b615';
var user1 = gs.getUserID();

var report = new GlideRecord('sysauto_report');
report.get('sys_id',sysid);

report.user_list = user1 + '';
report.update();

SncTriggerSynchronizer.executeNow(sysid);

Hope that makes sense? If you need the example inside a workflow do let me know

 

If my reply helped with your issue please mark helpful 👍 and correct if your issue is now resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having.

Hi, Checking in on whether my reply resolved your issue? If so please Mark Correct and /or 👍 Helpful if you find my response worthy based on the impact.
By doing so you help other community members find resolved questions which may relate to an issue they're having.

Thanks @

Kieran Anson
 
 
Kieran Anson
ITOM Developer at ITOM Solution
Correct Answers 50
Helpful Answers 100
SNUG Member
4,310 points - Community Level 5

Mwatkins
ServiceNow Employee
ServiceNow Employee

I tried this with a job that was type "On Demand" and it didn't do anything. I checked and jobs of type "On Demand" do not get picked up by the scheduler. I switched over to type "Once" and it worked like a charm. Now I can trigger my scheduled CSV export of a report to run whenever I want from code. I also needed to update some fields on the sys_report before sending it each time because my report filter can be easily made into a dynamic value. I did it by doing a GlideRecord.update against the sys_report record before triggering SncTriggerSynchronizer.executeNow(reportScheduledJobGR)

Please Correct if this solves your issue and/or 👍 if Helpful

"Simplicity does not precede complexity, but follows it"