- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2017 02:11 PM
Hello guys,
thanks for the last two posts where i did get so much help. I have another problem now by doing my first gliderecord.
I'm at this point so far (Client Script):
function onLoad() {
//Type appropriate comment here, and begin script below
var user = g_user.getFullName();
alert(user);
var a = new Array("Test 101", "Test 102");
var b = new Array("101", "102");
var qString = '';
for(var i=0; i<a.length; i++) {
var ir = new GlideRecord('sys_user_grmember');
ir.addQuery('group', a[i]);
ir.addQuery('user', user);
ir.query();
alert(a[i]);
if(ir.hasNext() == 'true'){
if (qString.length > 0) {
qString = "u_field=" + b[i];
} else {
qString += "^ORu_field=" + b[i];
}
} else {
qString = 'Test'; //just for testing
}
}
g_form.setValue('u_field2', qString);
}
I've put in some alerts to get the values of the variables at each point. And they do have the correct values at all time. But i didn't get any of the strings to my variable qString. I did manually check for the sys_user_grmember table and filtered for the user name (System Administrator) and the first group. I found one record. So there should be a result into the qString. Can somebody tell me what i did wrong there?
If you need further information, like always, feel free to ask. I'm really tired so please excuse me if i forgot something.
Greetings and all the best /Daniel
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2017 02:33 PM
Hi Daniel,
I modified your client script like below
function onLoad() {
//Type appropriate comment here, and begin script below
var user = g_user.userID;
alert(user);
var a = new Array("Test 101", "Test 102"); // update sys_id of group
var b = new Array("101", "102");
var qString = '';
for(var i=0; i<a.length; i++) {
var ir = new GlideRecord('sys_user_grmember');
ir.addQuery('group', a[i]);
ir.addQuery('user', user);
ir.query();
alert(a[i]);
if(ir.hasNext() == 'true'){
if (qString.length > 0) {
qString = "u_field=" + b[i];
} else {
qString += "^ORu_field=" + b[i];
}
} else {
qString = 'Test'; //just for testing
}
}
g_form.setValue('u_field2', qString);
}
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2017 02:33 PM
Hi Daniel,
I modified your client script like below
function onLoad() {
//Type appropriate comment here, and begin script below
var user = g_user.userID;
alert(user);
var a = new Array("Test 101", "Test 102"); // update sys_id of group
var b = new Array("101", "102");
var qString = '';
for(var i=0; i<a.length; i++) {
var ir = new GlideRecord('sys_user_grmember');
ir.addQuery('group', a[i]);
ir.addQuery('user', user);
ir.query();
alert(a[i]);
if(ir.hasNext() == 'true'){
if (qString.length > 0) {
qString = "u_field=" + b[i];
} else {
qString += "^ORu_field=" + b[i];
}
} else {
qString = 'Test'; //just for testing
}
}
g_form.setValue('u_field2', qString);
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2017 10:51 PM
Thanks to you guys. I did Change the Group Name to the sys_id. I had the userID at first for the user, but that didn't worked. Now i changed that again and nothing happens.
i added another alert after "if(ir.hasNext() == 'true'{" but i don't get this alert message at any Point of the code.
Does anyone has an idea?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2017 02:41 PM
- function onLoad() {
- //Type appropriate comment here, and begin script below
- var user = g_user.userID; // corrected require sysID
- alert(user);
- var a = new Array("Test 101", "Test 102"); // use the sys_id for the groups
- var b = new Array("101", "102");
- var qString = '';
- for(var i=0; i<a.length; i++) {
- var ir = new GlideRecord('sys_user_grmember');
- ir.addQuery('group', a[i]); // group is reference field
- ir.addQuery('user', user); // user is reference field
- ir.query();
- alert(a[i]);
- if(ir.hasNext()){ // corrected
- if (qString.length > 0) {
- qString = "u_field=" + b[i];
- }
- else {
- qString += "^ORu_field=" + b[i];
- }
- }
- else {
- qString = 'Test'; //just for testing
- }
- }
- g_form.setValue('u_field2', qString);
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 12:35 AM
Declare qString as array type since condition is checking length (Length method won't be work for String type).
var qString=[];
Add values to qString using push method.
or
If you want use it as - var qString=''; then modify the condition that qString!='' or qString=='' instead of use length .
Thanks,
Rajesh T