Lucien1
Giga Expert

Hi all,



Just to give an update, This is finally working which the guys at ServiceNow helped resolve. The below code sorted out the filter and still back-fill assignment groups.



var BackfillAssignmentGroup = Class.create();


BackfillAssignmentGroup.prototype = {


  initialize: function() {


  },



  BackfillAssignmentGroup:function() {


  var gp = ' ';


  var a = current.assigned_to;



  //return all groups that are not hidden if the assigned_to value is empty - Darren


  if(!a){


  var grph = new GlideRecord('sys_user_group');


  grph.addQuery('u_hidden',false);


  grph.query();


  while(grph.next()) {


  //build a comma separated string of groups


  gp += (',' + grph.sys_id);


  }


  }


  //sys_user_grmember has the user to group relationship


  var grp = new GlideRecord('sys_user_grmember');


  grp.addQuery('user',a);


  grp.addQuery('group.u_hidden',false); //Filter out approval groups - Darren


  grp.query();


  while(grp.next()) {


  if (gp.length > 0) {


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


  gp += (',' + grp.group);


  }


  else {


  gp = grp.group;


  }


  }


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


  return 'sys_idIN' + gp;


  },


  type: 'BackfillAssignmentGroup'


};




Hope this helps someone out there.



Regards,



Lucien


View solution in original post