How to pass array values to Table using GlideRecord ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2019 12:15 PM
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
}
}
}
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2019 12:19 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2019 01:00 PM
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