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

Hi Allen,

 

Do you know how I could  modify your script to only export a few specific fields on the form, instead of the whole form?

 

Thanks in advance for any help,

Carlos

Hi Allen,

 

First of all, thank you for this simply great solution!

 

I want to know if I don't want some fields on pdf, then what do I need to do?

Are there any scripts to avoid some specific fields, suppose from the incident table?

 

Thank you!

Hi Allen,

 

Can we do it for Powerpoint as well ? if yes, please let me know

It's working smoothly - Washignton DC        =D

The solution provided by @Allenovation requires the user from Employee Center read roles for the different types of records.
To develop something more suitable I'm using this Home - Documentation (rawgit.com) .

^^




Hi,

Thanks for confirming it's still good to go on the Washington version. As far as what I provided requiring any special roles, it only requires whatever is needed by the platform for the user to access the data, regardless of Employee Center. The user can't just print a PDF for data they don't have access to and my script doesn't cause any excess dependency than what is already required on their instance.

 

As far as using a 3rd party library to accomplish your requirement, that's neat to hear! ðŸ˜€


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