Advanced Reference Qualifier

divvi_vamsi
Mega Expert

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

1 ACCEPTED SOLUTION

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'  


});


View solution in original post

17 REPLIES 17

So, if i am right, the sys_ids being returned are sys_ids of user records from user table, as it is a reference field and 'sys_idIN' is checking if the current list of sys_ids being returned are IN u_members which is the reference table for current field.



So it is not returning anything/ everything as the condition is not satisfied. But not sure how to rectify this...



Thanks


Divya


few question,



var BackfillAssignmentGroups = Class.create();


BackfillAssignmentGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {


BackfillAssignGroups:function() {


var gp = [];


var a = current.u_group.toString(); //Are you getting the sys_id of group here?


if(!a)


return;


var grp = new GlideRecord('u_members');


grp.addQuery('u_code', a); //is u_code field is having the group sys_id?


grp.query();


while(grp.next())


gp.push(grp.sys_id.toString());


return 'sys_idIN' + gp;


},


type: ' BackfillAssignmentGroups'


});



what is there in u_mem field?


var a = current.u_group.toString(); //Are you getting the sys_id of group here?


Yes, it is returning the sys_id of the selected value on the form.



//is u_code field is having the group sys_id? --> this is a group code from a custom table which is being referenced by   u_members table, so it consist of a sys_id value in u_members.



u_mem field is basically a username field whose dictionary is a reference to sys_user table.



Thanks


Divya


so, u_mem field is a reference field to sys_user table? if yes, let's try in this way then



gp.push(grp.u_mem.toString());


Already tried that way shishir, didn't work.



Thanks