UI action to export specific fields to PDF

Carlos52
Tera Expert

Hi everyone,

 

I need to create an UI action to export certain fields from a ticket to a pdf file. I followed the instructions on previous topics - UI Action Button to Access Export > PDF Portrait and  UI Action to export a form to pdf , however the resulting pdf includes all the fields:

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

 

Does anyone know how to modify the previous code to only include certain fields?

Or alternatively how to create a pdf with only certain values.

 

Thanks in advance for any help,

Carlos

 

 

1 ACCEPTED SOLUTION

Fabian Kunzke
Kilo Sage
Kilo Sage

Hey,

as you are using a URL to get it exported to PDF the resulting PDF will contain the fields of the form view specified. In your case (if no view is specified) that view is the default view.

If you want different fields to be exported this way, the easiest approach is to create a new form view with only these fields. All you have to do is add the view to the URL

var url = instanceName+sysparm_table + '.do?PDF&sys_id=' + sysparm_sys_id + "&sysparm_view=PDF";

This should result in the PDF being created with the new view.

Note: you can make this view hidden, so a user cannot accidentally select it. This KB article describes it best.

Hope this helps,

Regards,
Fabian

View solution in original post

7 REPLIES 7

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Please go through my article

https://community.servicenow.com/community?id=community_article&sys_id=3e952432dbd81510847d5ac2ca9619cd

You need to create view, add those fields in view and pass it in your query like below

var url = '/' + g_form.getTableName() + '.do?sys_id=' + 
	  g_form.getUniqueValue() + '&sysparm_view=export_to_pdf&PDF';

 

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi Musab,

 

Thanks for your explanation, it helped me understand how to create the new view and configure it.

Unfortunately I don't have the "Format for configurable Workspace" checkbox, so maybe that's why it didn't export.

 

Cheers,

Carlos

Kalyani Jangam1
Mega Sage
Mega Sage

Hi,

"&sysparm_view=PDF" line should add. PDF view of record and includes only specific field