UI Action Button to Access Export > PDF Portrait

kshaw
Giga Guru

In effort to give better/simpler user experience to our non-technical agents, I want to create a UI Action Button "Export to PDF" that has the same functionality as the contextual menu item Export > PDF (Portrait).

However, in doing much searching on similar topics I have found no working solution and most responses are somewhat dated. The most recent reply that seemed to provide a solution just did not work in London on our instance.

It would seem a pretty simple thing to have an action that access the same function as the menu item.

Hoping for help in finding a working solution.

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

This can be achieved by creating a UI Action with the following settings:

Client: Checked

OnClick set to: exportPDF()

Show Update: Checked

Form Button: Checked

and script to this:

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

Change out instance_name in URL to your instance's subdomain.

Works on Madrid as I just did this.

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

18 REPLIES 18

Indeed. Nice job!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen, I have a similar requirement where in I am looking out for a way to download the attachment as CSV for the following requirement.

1. Download all the Application of Studio with Application files listed in table format something like 

#NameShort DescDesc
    
    

2. Also, I have a requirement to display the description or short description of different classes of metadata table like Business rule or UI policy,

If that is the case how to query different classes dynamically to get the values of the colu

I have a script drafted but need help to make this or style this in 

function copyApplicationfiles(gr) {

output("\n Application Files");
var classname = '';
var records = [];
var sno = 1;
while (gr.next()) {
//var shortdesc= gr.sys_scope.short_description;
//output("\n*** Application Name: " + gr.sys_scope.name);
//output(gr.sys_class_name + " class:"+ records.length + " Find: "+records.indexOf(gr.sys_class_name));
if(gr.sys_class_name != classname) {
classname = String(gr.sys_class_name);
sno = 1;
output("_______________________________________________________________________\n");
output("Class Name: " + gr.sys_class_name.getDisplayValue());
output('S.No\tName\tTable\tCreatedBy');
}

output(sno + '\t' + gr.sys_name + '\t' + gr.sys_class_name.getDisplayValue() + '\t' + gr.sys_created_by);
sno++;



}

}

function download(filename, data) {
var blankInc = new GlideRecord("ecc_queue");
blankInc.agent = "Background Script";
blankInc.topic = "Output: "+ filename;
blankInc.name = filename;
blankInc.source = "Application files";
blankInc.insert();
// Replace /t with ,
data = data.replace(/\t/g, ',');
var attachment = new Attachment();
var attachmentRec = attachment.write("ecc_queue", blankInc.sys_id.toString(), filename, "text/csv", data);
var attachRec = new GlideRecord("sys_attachment");
attachRec.addQuery("table_sys_id", blankInc.sys_id.toString());
attachRec.addQuery("file_name", filename);
attachRec.query();
attachRec.next();
var url = "/sys_attachment.do?sys_id="+attachRec.sys_id.toString()+"&view=true";
gs.print("\n\n");
gs.print("\n\n");
gs.setRedirect(url);
//blankInc.deleteRecord();
}
function output(str) {
fileoutputstr += str + '\n';
}

var fileoutputstr = "";
var appID = '0aa1393093213100ae6e941e867ffb40';
var gr = new GlideRecord("sys_metadata");
gr.addQuery('sys_scope', appID);
gr.orderBy('sys_class_name');
gr.query();
while(gr.next())
{
output("Application Name :" + gr.sys_scope.name);

copyApplicationfiles(gr);
download('ApplicationFiles_output.csv', fileoutputstr);
}

 

Viktor16
Tera Contributor

you could use gs.getProperty('instance_name') or gs.getProperty('glide.servlet.uri');

Aparna2
Kilo Explorer

I just want this same UI Action in the portal ticket summery page.

Could anyone help me