I am trying to do contextual search on cmdb_ci_service_auto table in virtual agent
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 08:30 AM
I am trying to do contextual search on cmdb_ci_service_auto table in virtual agent flow .
Please find my below script for contextual search on cmdb_ci_search_auto table.
(function execute(query) {
var results = [];
// Initialize contextual search utility
var contextualSearch = new global.VAGlobalContextualSearchUtil();
// Perform custom search on the cmdb_ci_service_auto table
var helperGR = new GlideRecord('cmdb_ci_service_auto');
helperGR.addQuery('name', 'CONTAINS', query)
.addOrCondition('aliases', 'CONTAINS', query);
helperGR.addQuery('u_show_in_portal', 'true');
helperGR.addQuery('install_status', '1');
helperGR.query();
// Fields to include in the results
var fields = [
"sys_id",
"name"
].join();
// Process the query results
while (helperGR.next()) {
var itemFields = {};
results.push({
sys_id: helperGR.getValue('sys_id'),
url: '?id=yit_app&sys_id=' + helperGR.getValue('sys_id'),
primary: helperGR.getDisplayValue('name'),
fields: itemFields,
type: 'app'
});
}
// Convert results to a format that Virtual Agent can use
vaVars.searchResultCount = results.length;
vaVars.search_result_json_string = JSON.stringify(results);
vaVars.index = 0;
// Prepare a summary of search results
var searchResultSummary = {};
for (var key = 0; key < results.length; key++) {
var id = results[key].sys_id;
var tableName = 'cmdb_ci_service_auto';
if (tableName in searchResultSummary) {
var resultSysIDList = searchResultSummary[tableName];
resultSysIDList.push(id);
searchResultSummary[tableName] = resultSysIDList;
} else {
searchResultSummary[tableName] = [id];
}
}
vaVars.ctx_search_details = JSON.stringify(searchResultSummary);
// Check if top result card is supported
vaVars.is_top_result_card_supported = false;
if (vaVars.searchResultCount > 0) {
vaVars.top_result_data = contextualSearch.processTopResultData(vaVars.search_result_json_string);
vaVars.is_top_result_card_supported = contextualSearch.isTopResultCardSupported(vaVars.top_result_data);
}
// Set the portal name if provided
vaVars.portalName = gs.nil(vaInputs.portal) ? vaVars.portalName : vaInputs.portal;
return;
})(vaInputs.query);
This script is not working it's not able to search on cmdb_ci_service_auto table
0 REPLIES 0