- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 03:14 AM
Hi all,
I have an array of asset tags, and I want to check in the cmdb_ci_server table to see if they are there.
I want to make it so that the function returns false if even one of the values in the array is not in the cmbd_ci_server.
I know I could do this as:
gr.addQuery('Asset Tag', assetTags[0]);
gr.addQuery('Asset Tag', assetTags[1]);
and so on, but I was wondering if there is a way for me to query the whole array?
Thank you for all your help!
G
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 03:21 AM
Hi @gunishi
You can convert array into String.
Then add encoded query
E.g., var array =[A100,B100]
var arrayStr = array.toString()
gr.addEncodedQuery("asset_tagIN" + arrayStr);
if (gr.next()){
//Record present
} else {
//Not present
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 03:21 AM
Hi @gunishi
You can convert array into String.
Then add encoded query
E.g., var array =[A100,B100]
var arrayStr = array.toString()
gr.addEncodedQuery("asset_tagIN" + arrayStr);
if (gr.next()){
//Record present
} else {
//Not present
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 03:24 AM
Thank you so much for the swift response.
This has helped me no end! Just to confirm, will this search for each asset tag in the aray individually?
G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 03:35 AM
Hi @gunishi
For this you can use for loop instead of if.
E.g.,
var result = false;
var array =[A100,B100]
var arrayStr = array.toString();
gr.addEncodedQuery("asset_tagIN" + arrayStr);
while (gr.next()){
result = true;
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 03:39 AM