logo

NJP

Populate Assigned to based on child assignment group

Import · Apr 25, 2019 · article

Populate Assigned to based on child assignment group

Below a Script include that populate the assigned to based in child assignment group, I have noticed that in service now when you choose an assignment group that have one or more children, then in the assigned to filed it shows you only the members of the parent group, it does not include all members : parent group + children groups.

1- Right click on the assigned to field then configure dictionary:

image

In the Dependent Field we delete the assignment_group as below:

image

In the Reference Specification let use an advanced user reference qualifier and in the reference qualifier add this code as below:

javascript:'role=itil'+new BackfillAssignedTo().BackfillAssignedTo()

image

2-Create a Script Include Called BackfillAssignedTo:

In system navigation type Script include under system definition then new,

Name = BackfillAssignedTo

Script:

var BackfillAssignedTo = Class.create();

BackfillAssignedTo.prototype = {

initialize: function() {

},

BackfillAssignedTo:function() {

var gp = ' ';

var a = current.assignment_group;

//return everything if the assignment_group value is empty

if(!a)

return;

var grp = new GlideRecord('sys_user_group');

grp.addEncodedQuery("name="+a+"ORparent="+a);

//grp.addQuery('parent',a);

grp.query();

var count = grp.getRowCount();

if (count >0){

//gs.addErrorMessage("When the group have childre get all members");

while(grp.next()) {

//sys_user_grmember has the user to group relationship

var sugmgr = new GlideRecord('sys_user_grmember');

var q1= sugmgr.addQuery('group',grp.sys_id).addOrCondition('group',a);//

q1.addQuery('group',grp.name);

sugmgr.query();

//build a comma separated string of groups if there is more than one

while (sugmgr.next())

{

if (gp.length > 0)

{

gp += (',' + sugmgr.user);

}

else

{

gp = sugmgr.user;

}

}

}

}

else {

//gs.addErrorMessage("When group does not have childre get only group members");

var sugmgr1 = new GlideRecord('sys_user_grmember');

sugmgr1.addQuery('group',a);//

sugmgr1.query();

//build a comma separated string of groups if there is more than one

while (sugmgr1.next())

{

if (gp.length > 0)

{

gp += (',' + sugmgr1.user);

}

else

{

gp = sugmgr1.user;

}

}

}

// return Groups where assigned to is in those groups we use IN for lists

return 'sys_idIN' + gp;

},

type: 'BackfillAssignedTo'

}

View original source

https://www.servicenow.com/community/csm-articles/populate-assigned-to-based-on-child-assignment-group/ta-p/2297272