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

hmmm....not sure about a condition running just on that field....sorry.


Thanks for your help though.



I will carry on searching. There has to be a way


ohhgr
Kilo Sage
Kilo Sage

Hi Lucien,



There doesn't seem to be a query in your second GlideRecord Call.



  var id = '';


  var gt = new GlideRecord("sys_user_group_type");


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


gt.query();


  if (gt.next()) {


  id = gt.sys_id;


  }



Please add it.



Also, you could merge these two in one GlideRecord query itself. Add one encoded query in your first GlideRecord condition as below



var grp = new GlideRecord('sys_user_grmember');


  grp.addEncodedQuery('typeLIKE+'add_type_sys_id_here+'^user='+a);


grp.query();



Hope that helps.


Mandar


Hi Mandar Kamtekar,



I tried the modifications you suggested, sadly didn't work and also stopped doing backwards filtering. I am wondering if these actions are meant to be separate or if they can merge together.



What are your thoughts.


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