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

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

NamrataJain
Tera Expert

Hi Ankit,

 

I tried your code, and it gives me error where it's says, "Page you are looking for cannot be found".

 

find_real_file.png

Hi Namrata,

It seems your ui action is calling ZIP not PDF according to your screenshot, check if you have PDF plugin already installed in your instance. Also use this code below, I have changed it to get your current instance name replacing the hard coding on it.

 

function exportPDF() {
    var sysparm_table = g_form.getTableName();
    var sysparm_sys_id = g_form.getUniqueValue().toString();
    var a=gs.getProperty("instance_name");
    var url = a+sysparm_table + '.do?PDF&sys_id=' + sysparm_sys_id;
    g_navigation.openPopup(url);
}