How to Change the Default name of the PDF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2024 11:34 PM
Hello Community,
I have a need to customize the default behaviour of PDF exports. Currently, when exporting a record as a PDF, the file is downloaded with the table name as the default.
I am looking for a solution to customize this behaviour so that the PDF is downloaded with the Ticket Numbers and Short Description instead. Despite searching through various community posts, I haven't found a suitable solution.
If anyone has insights on this, please assist.
Best Regards,
Sai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2024 07:38 PM
Hi @Ankur Bawiskar
Thanks for your reply.
I am Exporting from the Form by using the Export ---> PDF in the Context Menu Options.
Regards,
Sai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2024 08:36 PM
then try changing the code in this UI context menu and see if you can change the file name
https://instanceName.service-now.com/nav_to.do?uri=sys_ui_context_menu.do?sys_id=d1e5d8a50a0a0b3e00459c252c81e649
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2024 10:54 PM
Hello @Ankur Bawiskar,
I'm currently working with the script for the context menus, and I noticed that it includes the libraries GwtPollDialog and GwtExportScheduleDialog. However, I'm having difficulty pinpointing the exact location to add the code for my specific needs.
If you have any insights or suggestions, I would greatly appreciate your guidance on this matter.
Thank you,
Sai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2024 11:16 PM
no need to touch those GwtPollDialog and GwtExportScheduleDialog
you already have the record sysId in variable g_sysId
So query that with your table present in variable g_list.tableName and then get the field value
something like this. I hope this much is enough for you to proceed further
/**
* Script executed on the Client for this menu action
*
* The following variables are available to the script:
* 'g_list' the GlideList2 that the script is running against (only valid for List context menus)
* 'g_fieldName' the name of the field that the context menu is running against (only valid for List context menus)
* 'g_sysId' the sys_id of the row or form that the script is running against
* 'rowSysId' is also set to the sys_id of the row to support legacy actions, but g_sysId is preferred
*/
runContextAction();
function runContextAction() {
var sysparm_rows = g_list.grandTotalRows;
var num_rows = parseInt(sysparm_rows);
var sysparm_query = g_list.getQuery({all: true});
var fileName;
var gr = new GlideRecord(g_list.tableName);
gr.addQuery("sys_id", g_sysId);
gr.query();
if (gr.next()) {
fileName = gr.number + '-' + gr.short_description;
}
var sysparm_view = g_list.view;
if (num_rows < g_export_warn_threshold) {
var dialog = new GwtPollDialog(fileName, sysparm_query, sysparm_rows, sysparm_view, 'unload_pdf');
dialog.execute();
return;
}
var dialog = new GwtExportScheduleDialog(fileName, sysparm_query, sysparm_rows, sysparm_view, 'unload_pdf');
dialog.execute();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2024 11:28 PM
Hello @Ankur Bawiskar ,
We couldn't find a variable named "g_sysId" in the script. Despite attempting to replicate the steps you provided, the file is still downloading unexpectedly with the table name. Kindly review and offer your insights on this matter.
Regards,
Sai