Script to execute scheduled "on demand" report

staceyrocheleau
Kilo Guru

I read the wiki that says you can execute a scheduled report using the following:

---------

//Execute a scheduled script job var rec = new GlideRecord('sysauto_script'); rec.get('name', 'YOUR_JOB_NAME_HERE'); SncTriggerSynchronizer.executeNow(rec);

This script can be run using one of several tables:

  • scheduled_import_set (Scheduled Import Sets)
  • sysauto_script (Scheduled Script Execution)
  • sysauto_template (Scheduled Template Generation)
  • sysauto_report (Scheduled Report)

-----------

When I try this with my scheduled report (replace "sysauto_script" with "sysauto_report"), it doesn't do anything. Has anyone had any luck with this?

3 REPLIES 3

Anurag Tripathi
Mega Patron
Mega Patron

Hi Stacey,



I doubt that it will work, although if you do get it working please do post the solution. I would be interested.


-Anurag

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Stacey,



It should work. I've done a test on my own instance by creating a test report called "MyReport".



First I checked in background scripts that querying the sysauto_report gives me 1 record:



var rec = new GlideRecord('sysauto_report');


rec.get('name', 'MyReport');


rec.query();



gs.print(rec.getRowCount());



gets me:



[0:00:00.007] Script completed in scope global: script



*** Script: 1


Then I run the script itself:



var rec = new GlideRecord('sysauto_report');


rec.get('name', 'MyReport');


SncTriggerSynchronizer.executeNow(rec);



There is no output but then I went to System Logs -> Transactions (Background), sorted descending by Created and then saw my report job that run (it's only available once it finishes):



Screen Shot 2017-01-12 at 3.13.26 PM.png




All the jobs that are executed now will have the name "System Trigger <date>" as you can see in above screen shot. It's not going to have the name of my report.



Hope this helps.


Is it just running the report but not my scheduled report? Because what I would expect is the email to be generated but it never is. That's why I said it isn't really running. I checked the transaction logs and I don't see them. I see scheduled reports I ran directly but that's it.