Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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  ||  9x 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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader