Reference Qualifier advanced filter not working.

Lucien1
Giga Expert

Morning all,

We have decided to modify our change process and have created approval groups. All that works great and has made life a bit easier however, I can't seem hide these approval groups so users can assign tickets to these groups. This is still in development and is the last issue I have to resolve before pushing into production

So currently, my configuration is this.

1. I have a reference qualifier in place to back-fill assignment groups in a script includes. (This part works so am happy there ) I found the below script and have modified it look at the fields that

function HideApprovalGroups() {

  var gp = ' ';

  var a = current.assigned_to;

  //return everything if the assigned_to value is empty

  if(!a)

  return GetGroupFilter('Assignment Group') ;

  //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()) {

  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

  var results = 'sys_idIN' + gp;

  var id = '';

  var gt = new GlideRecord("sys_user_group_type");

  gt.addQuery("name", 'Assignment');

  if (gt.next()) {

  id = gt.sys_id;

  }

  results = 'sys_idIN' + gp + '^typeLIKE' + id;

  return results;

}

I have created 2 group types and they are called Approval and Assignment.

When I log a ticket (Itil user) I can see the approval groups.

Can anyone see where I have gone wrong?

Thank you,

Lucien

1 ACCEPTED SOLUTION

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

9 REPLIES 9

Victor Ruiz
Tera Guru

We implemented this solution and it works well: http://wiki.servicenow.com/index.php?title=Hiding_Groups#gsc.tab=0


Hi Victor Ruiz,



I did try this before but there was an issue. There is a group that are looking after our CMDB and when I tested this out, it stopped those users from being able to see the hidden groups.



Other than that, the business rule did everything I needed.



Is it possible to have the business rule only filter out on the "Assignment Group" fields?



Regards,



Lucien


Did you try adding your CMDB group to the condition?



(!gs.hasRole('admin') || !gs.hasRole('groups_admin')   || !gs.hasRole('CMDB')) && gs.getSession().isInteractive()



Yes and that is fine but then they can assign tickets to the approval groups in the assignment group field and that is what I am trying to stop from happening.



As the assignment group field is on the task table, can I put in a condition just to run on this field?



Thank you,



Lucien