Hey everyone i hope you can help me with a issue that i am having:
i use a function to get a list of groupmembers from a group.
this is being returned to a variable.
from this variable i need to see if my current user (current.sys.id
) is in this list.
if not do something if so do nothing.
unfortunately my .search
always returns -1 even if the record is in it.
i used the gs.log command to see diffrent outcomes and i see that the regexp is present in the var and even then it gives me a -1. can someone see what i am doing wrong?
here is my code
var list = group_members();
var check = new RegExp(current.sys_id);
var control = list.search(check);
if (control = -1) {
set_group();
gs.log("conf is :" + conf);
gs.log("check is :" + check);
gs.log("control is: " + control + "de lijst ziet er zo uit: " + list);
} else {
gs.log("check is :" + check);
gs.log("control is: " + control + "de lijst ziet er zo uit: " + list);
}
}
function group_members() {
gs.log("functie check groep is aangeroepen");
var answer = ' ';
var group = "794ac672d4a301006027eb6da8731188";
var group_mem = new GlideRecord('sys_user_grmember');
group_mem.addQuery('group', group);
group_mem.query();
while (group_mem.next()) {
if (answer.length > 0) {
answer += (',' + group_mem.user.sys_id);
} else {
answer = group_mem.user.sys_id;
}
}
return answer.toString();
}
function set_group() {
gs.log("functie set_groep is aangeroepen");
var rec1 = new GlideRecord('sys_user_grmember');
rec1.initialize();
rec1.user = current.sys_id;
rec1.group.setDisplayValue('TFPP Users');
rec1.insert();
gs.log("groep is nu gezet");
}
thanks in advance.