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.

How to pass array values to Table using GlideRecord ?

Virendra K
Kilo Sage

Hi All,

I am trying to build very simple logic, but record is not getting fetch using glide record.

I have list collector variable and I need check or compare specific value  ( var x ='Special Access for Team Member') among list collector selected values.

 

I am using below Team_role Onchange() script, but its not getting queried and moving into While loop.

I don't understand, whats is going wrong in below code ? please suggest .

========================================================================================

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
  

var list = g_form.getValue('team_role');
 var x ='Special Access for Team Member';

var array = list.split(',');
var xx;

for (var i=0; i < array.length; i++) {

var grm= new GlideRecord('u_team_roles');


grm.addQuery('u_team_roles','IN', array[i];     // even I used 'sys_id'  instead of "u_team_roles" as well
grm.query();

while(grm.next()){                                    // NOT ENTERING IN THIS WHILE LOOP
    g_form.addInfoMessage('If cond');    // this msg is not getting popup
    xx = grm.u_team_roles;
    
    g_form.addInfoMessage(xx);   // this msg is not getting popup
    
    if (x == xx ){
        g_form.addInfoMessage ('Hi ..true ');  // No  msg
    }
}

}
   
}

2 REPLIES 2

Elijah Aromola
Mega Sage

You shouldn't do GlideRecord queries on the client side. You should call script includes via glideajax. That being said, you are missing a ) on your grm.addQuery() line. 

Prateek kumar
Mega Sage

Try using a GlideAjax and Array is a reserved word in javaScript

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
  

var list = g_form.getValue('team_role');
 var x ='Special Access for Team Member';

var arr = list.split(',');
var xx;

for (var i=0; i < arr.length; i++) {

var grm= new GlideRecord('u_team_roles');


grm.addQuery('u_team_roles', arr[i]);     // even I used 'sys_id'  instead of "u_team_roles" as well
grm.query();

while(grm.next()){                                    // NOT ENTERING IN THIS WHILE LOOP
    g_form.addInfoMessage('If cond');    // this msg is not getting popup
    xx = grm.u_team_roles;
    
    g_form.addInfoMessage(xx);   // this msg is not getting popup
    
    if (x == xx ){
        g_form.addInfoMessage ('Hi ..true ');  // No  msg
    }
}

}
   
}

Please mark my response as correct and helpful if it helped solved your question.
-Thanks