The CreatorCon Call for Content is officially open! Get started here.

find sysid of existing group which is searched by name

ankit_sharma487
Kilo Guru

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

ankit_sharma487
Kilo Guru


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
Administrator
Administrator

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!

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!