- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2022 07:27 AM
Hi All,
I am new to ServiceNow and JavaScript. I have been trying to work on running a JavaScript query adapting what I have done elsewhere which works fine. However, I am wanting to do this now on top level CMDB_CI table in opposed to the asset_alm table, which means I am returning tons of information I do not want to see things like NICS and consumables etc. Is there a way to add more granular fields to this for example and model category = Mobile Phone, Laptop, Computer etc
I have done this before with the below
gr.addEncodedQuery('model_category=81feb9c137101000deeabfc8bcbe5dc4');//Computer Model Category
But I am unsure how to do consecutive or statements as I am looking for something like
Category=Hardware # Not Software
Model Category = Laptop OR Mobile OR Printer etc for example
I understand how to grab the model category GUI Hex from the XML file so it's really the code layout for these requests which I would then merge presumably into the code below which has come from another post on here which I can no longer find the link to reference as it was many weeks ago now. Presumably at Line 3 and 4 respectively.
getDuplicateAssetforAssignedTo: function() {
var str = [];
var gr = new GlideAggregate('cmdb_ci');
gr.addAggregate('COUNT', 'serial_Number');
gr.groupBy('serial_Number');
gr.addHaving('COUNT', '>', 1);
gr.query();
while (gr.next()) {
str.push(gr.getValue('serial_Number') + '');
}
return str.toString();
},
});
Any help will be much appreciated and thank you in advance for your help on the above.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2022 11:15 AM
Hello,
If you want to get the query of any filter just go to the table and apply the filter of your choice as below and click on run
Then once you clicked on Run just right click on the filter created and copy query
Then use the query in the ecodedquery of your code
model_category=81feb9c137101000deeabfc8bcbe5dc4^ORmodel_category=c9d5bc50c3031000b959fd251eba8fbc
Please mark answer correct/helpful based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2022 11:15 AM
Hello,
If you want to get the query of any filter just go to the table and apply the filter of your choice as below and click on run
Then once you clicked on Run just right click on the filter created and copy query
Then use the query in the ecodedquery of your code
model_category=81feb9c137101000deeabfc8bcbe5dc4^ORmodel_category=c9d5bc50c3031000b959fd251eba8fbc
Please mark answer correct/helpful based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 12:17 AM
That worked amazing thank you and can’t believe how simple when you know how!
Thank you for your assistance it is greatly appreciated.