Creating a button in the top right corner of the list view to download the Incident table list in Excel format in ServiceNow involves creating a new UI Action for the Incident table. UI Actions in ServiceNow allow you to add buttons, links, or context menu items on forms and lists, executing server-side code, client-side code, or both.
Follow these step-by-step instructions to achieve this:
Step 1: Navigate to UI Actions
- Log in to your ServiceNow instance as an administrator.
- In the Filter navigator, search for and select System UI > UI Actions.
Step 2: Create New UI Action
- Click on the New button to create a new UI Action.
- In the form that appears, fill out the fields accordingly:
- Name: Give your UI Action a clear, descriptive name. E.g., "Download Incidents to Excel".
- Table: Select "Incident [incident]" from the dropdown. This specifies the UI Action is for the Incident table.
- Action name: You can leave this blank; ServiceNow generates it from the Name.
- Show on: Check the List checkbox to allow this action to appear in the list view.
- List Banner Button: To place the button on the top right corner of the list, check this box.
Step 3: Insert Script for Export
In the Script field, insert a client-side script that initiates the download of the list view in Excel format. ServiceNow doesn't execute server-side code for list context actions, so you should use a URL to trigger the Excel download:
// This script constructs the URL to export the current list to Excel and then navigates to that URL.
(function() {
var url = "YOUR_INSTANCE_NAME.service-now.com/incident.do?CSV&sysparm_query=" + g_list.getFixedQuery();
// Opens the generated URL in a new tab/window to start the download. Consider opening in the same window if preferred.
window.open(url, "_blank");
})();
Replace YOUR_INSTANCE_NAME with the actual name of your ServiceNow instance. Note: The URL uses 'CSV' as the format, as directly downloading to Excel (XLS) might not be directly supported for security reasons in newer versions of ServiceNow. However, this CSV file can easily be opened in Excel.
Step 4: Provide Necessary Roles (Optional)
In the Roles field within the UI Action form, you can specify roles like itil or admin if you want to restrict this button to users with specific roles. Leave it blank to allow all users with access to the Incident table to see this button.
Step 5: Save
Click the Insert and Stay or Insert button at the bottom of the form to save your new UI Action.
When you now navigate to the Incident list view, you should see the "Download Incidents to Excel" button on the top right of the list banner. Clicking this button will trigger the download of the list view.
Note:
This solution uses a URL manipulation technique to initiate the download, leveraging ServiceNow's built-in capability to export lists to CSV, which can be opened in Excel. Be mindful of the amount of data and the performance impact large downloads might have. Also, the provided script is a basic example; it might need adjustments to account for specific requirements or limitations in your ServiceNow instance.
Remember that direct Excel format downloads could be restricted due to security settings or ServiceNow platform updates. Always test customizations in a sub-production or development instance before applying them to your production environment.