Can I prepare a view for PDF export and automatically switch views when exporting?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
I have a view for PDF export that is separate from the view the user operates.
One way to do this is to switch views each time the export is made, but if possible I'd like to automatically specify the view for PDF export when exporting.
Is this possible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Hi bonsai,
Yes, this is absolutely possible and is a great pattern to keep the UI clean while ensuring official documents use a strict layout.
You can achieve this by creating a Client-side UI Action. Instead of using the context menu, you construct a specific URL that passes the sysparm_view parameter directly to the PDF processor. This generates the file in the desired view without changing the user's current session view.
Here is the implementation:
Create a UI Action
Name: Export PDF (Custom View)
Client: Checked (true)
Form Context Menu: Checked (or Form Button)
Onclick: exportSpecialPDF()
The Script:
function exportSpecialPDF() { var sysId = g_form.getUniqueValue(); var tableName = g_form.getTableName(); var targetView = 'your_pdf_view_name'; // Replace with your actual view name // Construct the URL with the view parameter and the PDF flag var url = tableName + '.do?sys_id=' + sysId + '&sysparm_view=' + targetView + '&PDF'; // Open the download in a new window/tab so the current form doesn't reload g_navigation.open(url, '_blank'); }
Why this works: The &PDF processor respects the sysparm_view passed in the URL string independently of the view currently rendered in the user's browser frame.
If this response helps you solve the issue, please mark it as Accepted Solution.
This helps the community grow and assists others in finding valid answers faster.
Best regards, Brandão.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
how is user exporting? from some custom UI action on form?
share some details or screenshots
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
