find sysid of existing group which is searched by name

Not applicable

plz tell where the problem is in this code. this is not assigning the task to found group 

 

var groupSysID ;
var groupName = current.variables.group_name;
var gr = new GlideRecord("sys_user_group");
gr.addQuery("name", "groupName");
gr.query();
if (gr.next()) {
groupSysID = gr.sys_id;
gs.addInfoMessage("found group" + gr.sys_id);
task.assignment_group = groupSysID;
}

1 ACCEPTED SOLUTION

Not applicable


var groupName = current.variables.group_name;
var gr = new GlideRecord("sys_user_group");
gr.addQuery("name", groupName);
gr.query();
if (gr.next()) {
var groupSysID = gr.sys_id;
gs.addInfoMessage("found group" + gr.sys_id);
task.assignment_group = groupSysID;
}

 

 

 

 

** i used groupName in double quotes ("") which was creating problems

 

View solution in original post

8 REPLIES 8

Allen Andreas
Tera Patron

Hi,
You'd need to assign the groupsysID variable down after the gr.next with the gr.sys_id;
Currently, it's listed at the top with nothing...?
Also I think there's some other issues going on.

So try:

var groupName = g_form.getValue('group_name');
var gr = new GlideRecord("sys_user_group");
gr.addQuery('name', groupName);
gr.query();
if (gr.next()) {
var groupSysID = gr.sys_id;
gs.addInfoMessage("found group" + gr.sys_id);
task.assignment_group = groupSysID;
task.update();
}

Only part I'm unsure about is if your current.variables.group_name is correct? Double check that it's not u_group_name or whatever.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Not applicable

thanks but i was wrong i used groupName in "" and that was creating issue.

Hi,

Glad it all worked out.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hmm...I'm glad you figured out the answer and marked your own response as correct, but I suggested this 3 months ago, which somehow turned out to be the correct answer. Anyways, glad you got it.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!