Need help on implementing Custom Export functionality on UI Builder page.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
I have a requirement in UI Builder to implement Export functionality.
On click of the button - the records from the list based on the filter should be exported in Excel file.
tried below code, but still seems not working
/**
* @Param {params} params
* @Param {api} params.api
* @Param {any} params.event
*/
function evaluateEvent({api, event}) {
try {
// 1. Log incoming event payload for debugging
if (api && api.context && api.context.log) {
api.context.log.info("EvaluateEvent Script started. Event data:", event);
}
// 2. Specify table and filter criteria
const tableName = "incident";
const encodedQuery = "active=true";
// 3. Build the standard ServiceNow direct export URL
const downloadUrl = `/${tableName}_list.do?EXCEL&sysparm_query=${encodeURIComponent(encodedQuery)}&sysparm_default_export_fields=all`;
// 4. Log the generated URL output
if (api && api.context && api.context.log) {
api.context.log.info(`Generated Download URL: ${downloadUrl}`);
}
return {
route: null,
fields: null,
params: null,
redirect: null,
passiveNavigation: null,
title: null,
multiInstField: null,
targetRoute: null,
// 5. Inject the download target here
external: {
url: downloadUrl
},
navigationOptions: null
};
} catch (error) {
// 6. Catch and log any runtime errors securely
if (api && api.context && api.context.log) {
api.context.log.error("Error in evaluateEvent execution:", error);
}
return null;
}
}
Any help on this would be grateful.
Thanks
Sreesh
0 REPLIES 0