run a report from ui action

dhirajwakodikar
Kilo Expert

I want to run a report when i click a ui action called test:

find_real_file.png

I wrote this on the onclick field of ui action:

action.setRedirectURL('https://dev10361.service-now.com/sys_report_display.do?sysparm_report_id=22ef12f30f26620007753b8ce10...

This is the URL of the published report that i want to run on click of 'test' ui action.

This isn't working.

1 ACCEPTED SOLUTION

tonemking
Giga Expert

Hi,



Try this



function runReport(){



url = '<url of your report>'


var newWin = window.open(url);


newWin.document.getElementById('run-report').click();


}



to get the url of the report I opened the report i wanted and then opened the developer console. In the console type this.location.href and right click the link and copy the link address.



Screen Shot 2016-10-26 at 6.55.49 AM.png



Here is the UI action. Works for me.



Screen Shot 2016-10-26 at 6.56.42 AM.png



best,



Tone


View solution in original post

8 REPLIES 8

tonemking
Giga Expert

Hi,



Try this



function runReport(){



url = '<url of your report>'


var newWin = window.open(url);


newWin.document.getElementById('run-report').click();


}



to get the url of the report I opened the report i wanted and then opened the developer console. In the console type this.location.href and right click the link and copy the link address.



Screen Shot 2016-10-26 at 6.55.49 AM.png



Here is the UI action. Works for me.



Screen Shot 2016-10-26 at 6.56.42 AM.png



best,



Tone


Hi,



This worked but i dont want the report to be opened in a new tab. i want it to get opened in same tab.


Also, i am adding following code in the same function to run a scheduled report but it is not getting triggered:


function runReport(){



url = 'https://dev10361.service-now.com/sys_report_display.do?sysparm_report_id=22ef12f30f26620007753b8ce10...


var newWin = window.open(url);


newWin.document.getElementById('run-report').click();


  var gr = new GlideRecord('sysauto_report');



if (gr.get('3effde770f26620007753b8ce1050eb3')) {


SncTriggerSynchronizer.executeNow(gr);


  gs.log("done");


}


}



If i try separately only that piece of code(the one to trigger the scheduled report), it does work, but when i try as above, only report is running but not scheduled report.


Pradeep J
Kilo Guru

Hi



Run Report.PNG



onclick:



onGoToReportPortal()



Script:


function onGoToReportPortal() {


      var url = 'https://dev15160.service-now.com/sys_report_display.do?sysparm_report_id=5e61b5844ffe2200d18f3fb2811...


      window.location = url;


}


How to prevent it from opening in new tab ?