UI Action to export a form to pdf

addenkik
Kilo Explorer

I am trying to create a button to export my problem form to pdf. Is it possible to call Export > PDF > Portrait context menu using UI Action?

11 REPLIES 11

gaidem
ServiceNow Employee
ServiceNow Employee

Put this URL at the end of your instance:
nav_to.do?uri=sys_ui_context_menu.do?sys_id=d1e5d8a50a0a0b3e00459c252c81e649

This is where that code is placed. You should be able to reuse it for your needs.


Hi Matt,

I tried that but it redirects me to the PDF Context Menu form.

Thanks

Kalyan


gaidem
ServiceNow Employee
ServiceNow Employee

Correct, that's where the code is. You will have to transfer that code to a UI Action. There are some notes in there about available variables. I sent this so you could start by creating the UI Action with this code as a basis(needing some modification of course). For example, you will need to replace variable referencing the sys_id.

Give it a shot, post your code if it doesn't work and we can go from there.


kreddyT
Mega Contributor

Hi,



I tried the same piece of code in my UI Action but it is redirecting to the previous visited page. Please let me know if where I should make changes to this code. Here is the code I have been using,



runContextAction();




function runContextAction() {


   


    var sysparm_rows = g_list.grandTotalRows;


    var num_rows = parseInt(sysparm_rows);


    var sysparm_query = g_list.getQuery({all: true});


   


    var sysparm_view = g_list.view;


    if (num_rows < g_export_warn_threshold) {


          var dialog = new GwtPollDialog(g_list.tableName, sysparm_query, sysparm_rows, sysparm_view, 'unload_pdf');


          dialog.execute();


          return;


    }


    var dialog = new GwtExportScheduleDialog(g_list.tableName, sysparm_query, sysparm_rows, sysparm_view, 'unload_pdf');


    dialog.execute();


}