gaidem
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();


}


Brahmjeet
Giga Contributor

Hey addenkik,

 

You can create a UI Action form button with the folowing script to export the form to pdf :-

 

Client : ticked

Form Button : ticked

Onclick : exportPDF()

 

Script :

 

function exportPDF() {
var sysparm_table = g_form.getTableName();
var sysparm_sys_id = g_form.getUniqueValue().toString();
var a='https://dev00000.service-now.com/';
var url = a+sysparm_table + '.do?PDF&sys_id=' + sysparm_sys_id;
g_navigation.openPopup(url);

} 

 

NOTE : In var a write your own developer instance url.

I want the same thing but instead of PDF I want to export form data to Excel. Can you please guide me for this?

 

Thanks!!

geetanjali kinj
Kilo Explorer

how to create export to PDF as a button on incident form