- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 02:53 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 03:01 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 03:10 AM
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';
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 03:38 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 03:12 AM
Hi,
"&sysparm_view=PDF" line should add. PDF view of record and includes only specific field