Passing an Array to GlideRecord Query in the Workflow

VAIGAI_KOTHANDA
Giga Contributor

HI,

We need to pass an array value to the GlideRecord Query in the Workflow. We have used the following code to pass an array value.


var answer = [];
var app = current.functions.getDisplayValue();
var array = app.split(",");
//var array1 = new ArrayUtil().unique(array);
var grBS = new GlideRecord('u_ecare_choicevalues');

for (var i=0; i < array.length; i++) {
grBS.addQuery('u_name', array[i]);

grBS.query();

while(grBS.next())
  {
  answer.push(grBS.approval_group);
  }
}

Here the problem is , its taking the first value and its not taking running for the other values.

Can you please help us fix this issue.

1 ACCEPTED SOLUTION

HI Harish,



Thanks for the help.



I made some changes to the code and it is working now.



var answer = [];
var govap = current.functions.getDisplayValue();
gs.log('function1:'+govap);
var arrayVal = govap.split(",");
len = arrayVal.length;

for (var i=0; i<=len; i++) {

var grBS = new GlideRecord('u_ecare_demand_choicevalues');
//grBS.addQuery('u_name', arrayVal[i]);
grBS.addQuery('u_name','IN', arrayVal[i]);
grBS.query();

while(grBS.next())
{
answer.push(grBS.approval_group);
gs.log('function2:'+ arrayVal[i]);

}
gs.log('function3:'+ arrayVal[i]);
}




I queried through the for loop and got "grBS.addQuery('u_name','IN', arrayVal[i]);" instead of grBS.addQuery('u_name', arrayVal[i]); , therefore it is working now.




Thanks for the help Harish Murikinati and Mani kanta Korada .




View solution in original post

11 REPLIES 11

edwin_munoz
Mega Guru

Hi Vaigai, I think you need to declare grBS inside the for loop.


Harish Murikina
Tera Guru

Try below code now . It should work.



var answer = [];
var app = current.functions.getDisplayValue();
var arrayval = app.split(",");



//var array1 = new ArrayUtil().unique(array);




var len = arrayval.length;



for (var i=0; len>i; i++)


{


      var grBS = new GlideRecord('u_ecare_choicevalues');
      grBS.addQuery('u_name', arrayval[i]);


      grBS.query();


      while(grBS.next())
    {
          answer.push(grBS.approval_group);
    }


}


Hi Harish,



Below is the explanation of the requirement:-



For Example:- We have more than one value in the Glide List A. And suppose the values are 1 and 2.



Each Value 1 and 2 are having a field called Approval group.



We are trying to fetch both the Approval Groups, in case 1 and 2 are selected in the Glide list A.



Can you now explain if the code provided by you will help?



Actually i tried that and it didn't help.



Edwin Munoz



Thanks,


Vaigai


Have you tried the above code? it doesn't work?