- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2017 04:04 PM
I am trying to use the script include from Wiki;
Reference Qualifiers - ServiceNow Wiki --> javascript:new BackfillAssignmentGroup().BackfillAssignmentGroup()
I tried logging the values of the comma separated string, which is accurate, but the filter on the form doesn't work as expected. Not sure what is missing in there.
var BackfillAssignmentGroup = Class.create();
BackfillAssignmentGroup.prototype = {
initialize: function() {
},
BackfillAssignmentGroup:function() {
var gp = ' ';
var a = current.u_group; //custom field in current form
//return everything if the assigned_to value is empty
if(!a)
return;
//sys_user_grmember has the user to group relationship
var grp = new GlideRecord('u_members'); //my custom table
grp.addQuery('u_code',a); //custom field in u_members
grp.query();
while(grp.next()) {
if (gp.length > 0) {
//build a comma separated string of groups if there is more than one
gp += (',' + grp.u_mem); //custom field in current form
}
else {
gp = grp.u_mem;
}
}
gs.log(gp);
// return Groups where assigned to is in those groups we use IN for lists
return 'sys_idIN' + gp;
},
type: 'BackfillAssignmentGroup'
};
Reference Qual: javascript:new BackfillAssignmentGroup().BackfillAssignmentGroup()
can someone please help with what is missing in here!!!
Thanks
Divya
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2017 09:24 PM
Can you try this code and see if this helps.
Reference Qual: javascript:new BackfillAssignmentGroup().BackfillAssignGroup()
var BackfillAssignmentGroups = Class.create();
BackfillAssignmentGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
BackfillAssignGroups:function() {
var gp = [];
var a = current.u_group.toString();
if(!a)
return;
var grp = new GlideRecord('u_members');
grp.addQuery('u_code', a); //Hope u_code is a reference field and it's having a details of groups.
grp.query();
while(grp.next())
gp.push(grp.sys_id.toString());
return 'sys_idIN' + gp;
},
type: ' BackfillAssignmentGroups'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2017 04:21 PM
The Script Include doesn't know what current is, so you need to pass current.u_group to your Script Include.
Reference Qual: javascript:new BackfillAssignmentGroup().BackfillAssignmentGroup(current.u_group)
var BackfillAssignmentGroup = Class.create();
BackfillAssignmentGroup.prototype = {
initialize: function() {
},
BackfillAssignmentGroup:function(groupId) {
if (!groupId) {
gs.log('No group ID');
return '';
}
var list = [];
//sys_user_grmember has the user to group relationship
var grp = new GlideRecord('u_members'); //my custom table
grp.addQuery('u_code', groupId); //custom field in u_members
grp.query();
while(grp.next()) {
list.push(String(grp.u_mem));
}
gs.log('list: ' + list.join(', '));
// return Groups where assigned to is in those groups we use IN for lists
return 'sys_idIN' + list.join(',');
},
type: 'BackfillAssignmentGroup'
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2017 04:45 PM
current works in script include.
here you go.
Script Include:
var hellows = Class.create();
hellows.prototype = {
initialize: function() {
},
BackfillAssignmentGroup:function() {
var gp = [];
var a = current.u_user;
//return everything if the assigned_to value is empty
if (!a)
return;
//sys_user_grmember has the user to group relationship
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user',a);
grp.query();
while (grp.next()) {
gp.push(grp.getValue('group'));
}
// return Groups where assigned to is in those groups we use IN for lists
return 'sys_idIN' + gp.join(',');
},
type: 'hellows'
};
Advance Reference qualifier: javascript:new hellows().BackfillAssignmentGroup()
testing. if you see below same users available in two different group.
output:
Final Result:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2017 08:27 PM
Hi Harshvardhan,
Any idea, why my script isn't working? For empty fields it's is displaying all the values, which is expected...but when a value is given in dependent field, it displays an empty lookup.
Thanks
Divya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2017 09:06 PM
Please check if there is any dictionary override which is causing an issue and also please remove the value from the dependent field if there are any and try.