We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Pass array in GlideRecord query

Servicenow Use4
Kilo Guru

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!

 

 

1 ACCEPTED SOLUTION

Hi,

is array contains CI sys_ids then do this

taskCIObject.addQuery('ci_item', 'IN', arr.toString());

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Hi,

is array contains CI sys_ids then do this

taskCIObject.addQuery('ci_item', 'IN', arr.toString());

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader