- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 11:23 PM
Hello!
I am trying to pass an array of values to addQuery, but I am not getting the desired output.
Form a previous code snippet, I get an array of CI sys IDs (arrayCI, suppose), which is also correct. I have verified that. I have to pass this array to below gliderecord.
Below is that sample of code:
var totalCount=0;
var taskCIObject = new GlideRecord('task_ci');
taskCIObject.addEncodedQuery(<<some encoded query>>); //which is working fine
taskCIObject.addQuery(<<pass the array that I got previously>>); //not sure of the syntax
taskCIObject.query();
while(taskCIObject.next())
{ totalCount = totalCount +1;} //the count is getting wrongly computed
gs.addInfoMessage('Count = '+totalCount);
I want to get the count of records for which the set of CIs is exact same.
Can anyone please help me solve the above?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2021 12:34 AM
Hi,
is array contains CI sys_ids then do this
taskCIObject.addQuery('ci_item', 'IN', arr.toString());
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 11:28 PM
Hi,
for querying with multiple values present in array use this syntax
var arr = ['sys_id1','sys_id2','sys_id3'];
taskCIObject.addQuery('fieldName', 'IN', arr.toString()); //not sure of the syntax
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 11:59 PM
Hi Ankur!
I tried taskCIObject.addQuery('fieldName', 'IN', arr.toString())
but the output is still incorrect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2021 12:02 AM
Hi,
are you using correct field name and comparing with correct array values.
Example this should work fine for incident and caller
var arr = ['userSysId1','userSysId2'];
var rec = new GlideRecord('incident');
rec.addQuery('caller_id', 'IN', arr.toString());
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2021 12:23 AM
Hi.. yes the column names are correct.. my requirement is "I want to get the count of records for which the set of CIs is exact same."
The set is of CIs is an array. Table 'task_ci' stores the Affected CIs for Change and other task types... I need to know how many change requests exists for which exact same CIs are present under Affected CI tab in change form.