I want to generate a excel file of selected records in a list?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 09:07 PM
Hi All,
I want to generate a excel report of selected records in a list, when the user clicks on 'Generate Excel Report' UI action(List Choice),created by me.
Is there a way I could do this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 09:20 PM
Hi.
Does this article seem useful?
インシデントでExcelとしてエクスポートを複製するにはどうすればよいですか...- ページ 3 - ServiceNow コミュニティ
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 10:17 PM
Hello Shibasou,
Yes I tried, but not as per my requirement because it is download based on the view.
I need to download the excel file based on the columns shown on the list layout by user when he clicks on this button
Can you please help me with the same.
Regards,
Shrey Khurana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 09:46 PM
Hi @Shrey hurana
Step 1: Create the UI Action
1. Navigate to System Definition > UI Actions.
2. Click New to create a new UI Action.
3. Fill in the fields:
- Name: Give your UI Action a descriptive name, e.g., “Generate Excel Report”.
- Table: Choose the table from which you want to generate the report, e.g., Incident.
- Action name: This is automatically filled based on the Name, but you can customize it.
- Client: Check this box since we’ll use client-side code to capture selected records.
- List: Check this box to make this UI Action appear in the list context menu.
- Form: You might leave this unchecked if you don’t want it to appear in form view.
Step 2: Scripting the UI Action
function() {
// Use the GlideList2 API to get the current list and the sys_ids of selected items
var sysIds = g_list.getChecked(); // captures the sys_ids of selected records
// Check if at least one record is selected
if (sysIds) {
// Construct the URL to export the selected records to Excel
var url = 'YOUR_INSTANCE_NAME/xlsx.do?sysparm_sys_ids=' + sysIds + '&sysparm_table=YOUR_TABLE_NAME';
// Open the URL to initiate download (replace YOUR_INSTANCE_NAME and YOUR_TABLE_NAME with actual values)
window.open(url, '_blank');
}
else {
// If no record is selected, alert the user
alert("Please select at least one record.");
}
}
Replace YOUR_INSTANCE_NAME with your ServiceNow instance name.
- Replace YOUR_TABLE_NAME with the actual table name you’re targeting, corresponding to the table you set for the UI Action.
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 10:19 PM
Thank you for the response.
It did not worked.
Please find below attached screenshots.
Request you to please help me with the same.