How to use query records with an array?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 12:23 PM
I am having an array with these values..
var arr = [10, 20, 30, 40];
var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0003440');
if(gr.next())
{
var getCode = gr.code;
if (arr.indexOf(getCode) != -1) { ----> Instead of written this indexOf .. is there any other alternate way?
arr2.push(gr.number)
}
Labels:
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 01:53 PM
I think indexOf will be the easiest and quickest way to do what you're looking for.
Otherwise, you could loop through the array looking for a match. It also looks like you might not be executing the query.
var arr = [10, 20, 30, 40];
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('number', 'INC0003440');
incidentGR.query();
var arr2 = [];
if(incidentGR.next()){
var getCode = gr.code;
if (arr.indexOf(getCode) > -1) {
arr2.push(gr.number);
}
OR
var arr = [10, 20, 30, 40];
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('number', 'INC0003440');
incidentGR.query();
var arr2 = [];
if(incidentGR.next()){
var getCode = gr.code;
for(code in arr) {
if(getCode == arr[code]) {
arr2.push(incidentGR.number);
break;
}
}
}