The CreatorCon Call for Content is officially open! Get started here.

Get Query Array

traviswarren
Kilo Expert

Hello all,

I am having an issue with my Get query array.   I am attempting to add a security group to the variable workflow.scratchpad.group.   Only one record must be set at a time due to me using this workflow.scratchpad.group variable for a powershell script.  

My intent is to get all matching records in a array then parse it with a split separated by commas.   With position, update workflow.scratchpad.group for the first record, then the second record and so on until there is no more records left.   I have a checker to identify when there is no more records. which is not documented below.

Here is my code below.

Any help is appreciated Thanks.

workflow.scratchpad.dlPosition = 0;

getGroup(workflow.scratchpad.dlPosition);

function getGroup(position) {

var gr = new GlideRecord('u_user_role_privilege');

if(gr.get('u_location', workflow.scratchpad.locationOfGroup[position])){

workflow.scratchpad.group = gr.u_dn;

workflow.scratchpad.dlPosition++;

}

}

var groupArr = [];

var list;

var rolePrivilege = new GlideRecord('u_user_role_privilege');

rolePrivilege.addQuery('u_location',workflow.scratchpad.location);

rolePrivilege.query();

while(rolePrivilege.next())

{

  groupArr.push(rolePrivilege.u_location.toString());

}

for(var count=0; count< groupArr.length; count++)

{

  list = groupArr[count];

  workflow.scrathpad.locationOfGroup = list.split(',');

}

1 ACCEPTED SOLUTION

Edwin,



Thanks everyone for putting your minds together on this matter.   I will show you what I believe is working now.



Determine array


var groupArr = [];


var list;


var rolePrivilege = new GlideRecord('u_user_role_privilege');


rolePrivilege.addQuery('u_location',workflow.scratchpad.location);


rolePrivilege.query();


while(rolePrivilege.next())


{


  groupArr.push(rolePrivilege.u_ad_group.toString());


}


workflow.scratchpad.locationOfGroup = groupArr;



Get Query


getGroup(workflow.scratchpad.dlPosition);


function getGroup(position) {


var gr = new GlideRecord('u_user_role_privilege');


if(gr.get('u_ad_group', workflow.scratchpad.locationOfGroup[position])){


workflow.scratchpad.group = gr.u_dn;


workflow.scratchpad.dlPosition++;


}


}



ifScript Any more Records?



answer = ifScript();




function ifScript() {


    if (workflow.scratchpad.locationOfGroup.length > workflow.scratchpad.dlPosition) {


          return 'yes';


    }


    return 'no';


}



I also found a spelling error too which could have been another issue.



Thanks again!


View solution in original post

8 REPLIES 8

Edwin,



Thanks everyone for putting your minds together on this matter.   I will show you what I believe is working now.



Determine array


var groupArr = [];


var list;


var rolePrivilege = new GlideRecord('u_user_role_privilege');


rolePrivilege.addQuery('u_location',workflow.scratchpad.location);


rolePrivilege.query();


while(rolePrivilege.next())


{


  groupArr.push(rolePrivilege.u_ad_group.toString());


}


workflow.scratchpad.locationOfGroup = groupArr;



Get Query


getGroup(workflow.scratchpad.dlPosition);


function getGroup(position) {


var gr = new GlideRecord('u_user_role_privilege');


if(gr.get('u_ad_group', workflow.scratchpad.locationOfGroup[position])){


workflow.scratchpad.group = gr.u_dn;


workflow.scratchpad.dlPosition++;


}


}



ifScript Any more Records?



answer = ifScript();




function ifScript() {


    if (workflow.scratchpad.locationOfGroup.length > workflow.scratchpad.dlPosition) {


          return 'yes';


    }


    return 'no';


}



I also found a spelling error too which could have been another issue.



Thanks again!


Looks good Travis! Glad it's working now.


TJW2
Mega Guru

Is this your issue here:


for(var count=0; count< groupArr.length; count++)  


{  


  list = groupArr[count];  


  workflow.scrathpad.locationOfGroup = list.split(',');  


}  



Do you need the for loop?


workflow.scrathpad.locationOfGroup = groupArr.split(',');  


I think that would throw an error since array doesn't have a split method.




He can populate the scratch variable directly in the while loop I guess.