- 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: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:43 AM
Hey Fabian,
Thanks for your help, that worked!
It is a shame that the pdf is still created with some extra info that is not needed (who requested the pdf, at what time, etc) but at least only the fields on that view are printed. 🙂
Cheers,
Carlos
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 01:36 PM
Hey @Carlos52 How can we make it work if we have dependent fields? For eg: the PDF displays all the fields in that current view even if that field is not on the form because it is a dependent field. How do we cater that scenario to only show dependent field when they are being set?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 03:08 AM
Hi,
you can check point mentioned by Fabian and share us the update once you try that out.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader