- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2017 02:51 AM
I have the below Detailed Scripts in Portal Query Widget, that Queries the CMDB and simply lists values that can be searched.
The idea is it should only include data from the Business Services (cmdb_ci_service), software (cmdb_ci_spkg), application (cmdb_ci_appl).
What needs to change in my scripts to only show data from these tables and not the entire CMDB, for the same columns detailed from each table.
Please help guide me through if you can.
I have the following Client Script:
function($scope, spUtil)
{
/* widget controller */
var c = this;
$scope.orderField = "ci_name";
$scope.changeSort = function(field)
{
$scope.orderField = field;
};
/* Use an OOB ServiceNow watcher
this makes the UI watch the data tables and update
on changes */
spUtil.recordWatch($scope, "cmdb_ci", "", function(name, data) {
spUtil.update($scope);
});
}
The following Server Script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.configitems=[];
var gr = new GlideRecord('cmdb_ci');
gr.addActiveQuery();
gr.setLimit(1000);
gr.orderByDesc('sys_updated_on');
gr.query();
while(gr.next())
{
var link_id = '';
var kgr = new GlideRecord('kb_knowledge');
kgr.addQuery('number', gr.getDisplayValue('u_knowledge_based_article'));
kgr.query();
if(kgr.next()){
link_id = gs.getProperty('glide.servlet.uri') + '/sp?id=kb_article&sys_id=' + kgr.sys_id;
}
var sc_link_id = '';
var sc_gr = new GlideRecord('sc_cat_item');
sc_gr.addQuery('sys_id', gr.u_catalog_item);
sc_gr.query();
if(sc_gr.next()){
sc_link_id = gs.getProperty('glide.servlet.uri') + '/sp?id=sc_cat_item&sys_id=' + sc_gr.sys_id;
}
var cmdb_ci = {};
cmdb_ci.name = gr.getDisplayValue('name');
cmdb_ci.sys_class_name = gr.getDisplayValue('sys_class_name');
cmdb_ci.category = gr.getDisplayValue('category');
cmdb_ci.short_description = gr.getDisplayValue('short_description');
cmdb_ci.sys_id = gr.getUniqueValue();
cmdb_ci.sys_updated_on = gr.getValue('sys_updated_on');
cmdb_ci.owned_by = gr.getDisplayValue('owned_by');
cmdb_ci.u_knowledge_based_article = gr.getDisplayValue('u_knowledge_based_article');
cmdb_ci.u_knowledge_sys_id = link_id;
cmdb_ci.u_catitem_sys_id = sc_link_id;
cmdb_ci.u_catalog_item = gr.getDisplayValue('u_catalog_item');
cmdb_ci.u_gold_standard = gr.getDisplayValue('u_gold_standard');
cmdb_ci.u_business_systems_catalog_tag = gr.getDisplayValue('u_business_systems_catalog_tag');
cmdb_ci.u_1st_line_support = gr.getDisplayValue('u_1st_line_support');
data.configitems.push(cmdb_ci);
}
/*
required iorder
name
class name
category
description
owned by
*/
})();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2017 04:01 AM
Hi,
Can you please try it in fix or background script.
I did it with this condition and it gave me filtered result set.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2017 03:43 AM
Hi Ubaid,
You can try by adding a query for classname in cmdb_ci table itself.
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('sys_class_name','cmdb_ci_spkg').addOrCondition('sys_class_name','cmdb_ci_service').addOrCondition('sys_class_name','cmdb_ci_appl');
gr.addActiveQuery();
This will filter out CI from these 3 tables only.
Please mark the response correct/helpful based on the impact.
Thanks
Gaurav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2017 03:49 AM
Hi Gaurav,
No that did not filter it.
Regards
Ubaid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2017 04:01 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2017 05:39 AM
I would say define a property with desired classes and call the property in the code