Read Interactive Filters
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2024 12:41 AM
Hey everyone,
I have been working on a script which will read all the filters associated with particular dashboard..At present the script is returning all the available filters from the system...I need script should only return the filters associated with queried dashboard...I know that there is no direct relation as such...OR based on reports fetched I need to check if filter is applied or not...Not sure how to approach here? Anybody can suggest me anything, would be of great help.
Thank you in advance!
I am using below code-
var dashboardSysId ='6ecb9e5747a40250c3604b44846d4354';//any random dashboard sysid
// Function to retrieve interactive filters associated with the dashboard
var getInteractiveFilters = function(dashboardSysId) {
var interactiveFilters = [];
var interActiveFilterGR = new GlideRecord('sys_ui_hp_reference');
interActiveFilterGR.addQuery('portal_section', dashboardSysId);
interActiveFilterGR.query();
while (interActiveFilterGR.next()) {
interactiveFilters.push({
sys_id: interActiveFilterGR.getValue('sys_id'),
name: interActiveFilterGR.getValue('name')
});
}
return interactiveFilters;
};
// Function to retrieve other types of filters applied on the dashboard
var getOtherFilters = function(dashboardSysId) {
var otherFilters = [];
// Add logic to retrieve other types of filters (dynamic filters, scripted filters, etc.) associated with the dashboard
// For example:
// var dynamicFilters = ...
// var scriptedFilters = ...
// For demonstration purposes, let's assume we retrieved dynamic filters and scripted filters
var dynamicFilters = [];
var dynamicFilterGR = new GlideRecord('content_block_static');
dynamicFilterGR.addQuery('dashboard', dashboardSysId);
dynamicFilterGR.query();
while (dynamicFilterGR.next()) {
otherFilters.push({
type: 'Dynamic Filter',
name: dynamicFilterGR.getValue('name')
});
}
var scriptedFilters = [];
var scriptedFilterGR = new GlideRecord('content_block_programmatic');
scriptedFilterGR.addQuery('dashboard', dashboardSysId);
scriptedFilterGR.query();
while (scriptedFilterGR.next()) {
otherFilters.push({
type: 'Scripted Filter',
name: scriptedFilterGR.getValue('name')
});
}
return otherFilters;
};
// Main execution
var interactiveFilters = getInteractiveFilters(dashboardSysId);
var otherFilters = getOtherFilters(dashboardSysId);
// Output the retrieved filters
gs.info("Interactive Filters:");
interactiveFilters.forEach(function(filter) {
gs.info("Name: " + filter.name + ", sys_id: " + filter.sys_id);
});
gs.info("Other Filters:");
otherFilters.forEach(function(filter) {
gs.info("Type: " + filter.type + ", Name: " + filter.name);
});
0 REPLIES 0