- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 01:13 AM
Has anyone come across/needed to change the default file name for an excel table export to not be the table name and be something custom instead?
The use case here is a custom app I have created for customers to complete staff pay assessments, calculate increases, overpayments, etc. As part of this the companies using it want to be able to download a copy of their
data into excel. This is all up and running and a database view has been created and the following function used to trigger the download from a button in the portal.
query = "u_hidden=false^u_hr_case=" + $scope.selectedAccount.hr_case_id + '^ORDERBYtcp_u_surname';
view = 'export';
table = 'sn_hr_core_assessment_download';
if (query != '' && view != '' && table != '') {
var t = top.window.open("/" + table + ".do?EXCEL&sysparm_query=" + query + "&sysparm_view=" + view);
}
This works fine and has been in use for a little while but to tidy it up I would like to rename the export if possible BEFORE it hits the customer machine (so they have no need to rename it manually afterwards).
Any ideas on how this could be achieved would be appreciated, thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 02:09 AM
Yes, it is possible to change the default file name for an Excel table export in ServiceNow. However, it requires a bit of scripting and customization. Here are the steps:
1. Create a UI Action on the table you want to export.
2. In the UI Action, you can use the 'exportWithLabel()' function to export the table data.
3. The 'exportWithLabel()' function accepts two parameters: the format of the export file (in this case, 'xls') and the custom name you want to give to the file.
4. The custom name should be a string and it will be used as the file name for the exported Excel file.
Here is a sample code for the UI Action:
javascript
var exportName = 'CustomFileName'; // Replace with your custom file name
var table = current.getTableName(); // Get the table name
var exporter = new ExportWithLabel('xls', exportName);
exporter.exportRecords(table, current.getEncodedQuery());
Please note:
- This will only change the file name for the exports triggered by this UI Action. The default 'Export' option in the table will still use the table name as the file name.
- Be careful with the file name. It should not contain any characters that are not allowed in file names.
- This customization might not be upgrade-safe. If ServiceNow changes the way exports work in a future update, this customization might stop working.
nowKB.com
For a good and optimistic result, and solving ServiceNow-related issues please visit this website.https://nowkb.com/home
Kindly mark correct and helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 02:09 AM
Yes, it is possible to change the default file name for an Excel table export in ServiceNow. However, it requires a bit of scripting and customization. Here are the steps:
1. Create a UI Action on the table you want to export.
2. In the UI Action, you can use the 'exportWithLabel()' function to export the table data.
3. The 'exportWithLabel()' function accepts two parameters: the format of the export file (in this case, 'xls') and the custom name you want to give to the file.
4. The custom name should be a string and it will be used as the file name for the exported Excel file.
Here is a sample code for the UI Action:
javascript
var exportName = 'CustomFileName'; // Replace with your custom file name
var table = current.getTableName(); // Get the table name
var exporter = new ExportWithLabel('xls', exportName);
exporter.exportRecords(table, current.getEncodedQuery());
Please note:
- This will only change the file name for the exports triggered by this UI Action. The default 'Export' option in the table will still use the table name as the file name.
- Be careful with the file name. It should not contain any characters that are not allowed in file names.
- This customization might not be upgrade-safe. If ServiceNow changes the way exports work in a future update, this customization might stop working.
nowKB.com
For a good and optimistic result, and solving ServiceNow-related issues please visit this website.https://nowkb.com/home
Kindly mark correct and helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 02:30 AM
That looks promising, thank you. Shall give it a go and mark as the solution if it does the trick from the portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 01:57 AM
Thanks sir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 09:11 AM
I have tried to replicate the same and it did not work. Can you please share more specifications like clientSide/ServerSide , listCompactibilities etc.