Reference Qualifier on a User Reference Field to show only Managers

nicksoltis
Kilo Expert

I am having trouble finding a way to limit a User Reference field to only show managers when selecting a user.

Below are fields on the "sys_user" table that would relate them to a Manager:

Capture.JPG

Capture2.JPG

Captur3e.JPG

****All of the colored out values are user referenced names****

Let me know if this is possible in a simple JavaScript condition statement or if it needs to be done externally from the fields dictionary in a Script Include.

Thank You,

1 ACCEPTED SOLUTION

nicksoltis
Kilo Expert

Here is the solution I have created. It works quite well.



BackfillUser:function(){


  var idList = ' ';



  var a = current.user;


  if(!a){


  return;


  }



  var user = new GlideRecord('sys_user');


  user.addQuery('managerISNOTEMPTY');


  user.addActiveQuery();


  user.query();


  while(user.next()){


  if(idList.length > 0){


  idList += (',' + user.manager.sys_id);


  }


  else{


  idList = user.manager.sys_id;


  }


  }



  return 'sys_idIN' + idList;


  },


View solution in original post

11 REPLIES 11

this seems to be missing the function initialization, can you provide the full script?


My finished modified version includes a couple more pulls/techniques of pulling others associated with manager.


Script below:



var getUsersByManager = Class.create();


getUsersByManager.prototype = {


      initialize: function() {


      },



  BackfillUser:function(){


  var idList = ' ';



//Gets users who are listed as managers of other users


  var user = new GlideRecord('sys_user');


  user.addQuery('managerISNOTEMPTY');


  user.addActiveQuery();


  user.query();


  while(user.next()){


  if(idList.length > 0){


  idList += (',' + user.manager.sys_id);


  }else{


  idList += (',' + user.manager.sys_id);


  }


  }



//Gets users who are listed as group managers


  var group = new GlideRecord('sys_user_group');


  group.addQuery('managerISNOTEMPTY');


  group.addActiveQuery();


  group.query();


  while(group.next()){


  if(idList.length > 0){


  idList += (',' + group.manager.sys_id);


  }


  else{


  idList += (',' + group.manager.sys_id);


  }


  }



//Gets users who have "Engagement Manager" in their title


  var user2 = new GlideRecord('sys_user');


  user2.addQuery('titleLIKEEngagement Manager');


  user2.addActiveQuery();


  user2.query();


  while(user2.next()){


  if(idList.length > 0){


  idList += (',' + user2.sys_id);


  }


  else{


  idList += (',' + user2.sys_id);


  }


  }




  return 'sys_idIN' + idList;


  },




      type: 'getUsersByManager'


};



//Builds a list and returns the list values


hmm... not working when I create a script include and then call it from an advanced ref qual field... doesn't filter down the user list at all


1. Validate the call:                   javascript: new getUsersByManager().BackfillUser()



2. Make it is on the dictionary of a user referenced variable



3. The code I gave you above was built for the system I was working on, it can be user specific, so comment out each of the query list builders.


        For example:


**comment this out, then test**


//Gets users who have "Engagement Manager" in their title


/*


  var user2 = new GlideRecord('sys_user');


  user2.addQuery('titleLIKEEngagement Manager');


  user2.addActiveQuery();


  user2.query();


  while(user2.next()){


  if(idList.length > 0){


  idList += (',' + user2.sys_id);


  }


  else{


  idList += (',' + user2.sys_id);


  }


  }


*/



4. Ensure that if you copy and pasted my code into a script include that you did not keep and repeat the initialiation



5. Validate that the name of your script include matches getUsersByManager



6. Last, ensure that if you copy and pasted my code, values copied are being read by the editor.


        For example:



        -values inside of "" or '' can sometime not be read by editors



If this still does not solve your problem, let me know.


2. Make sure**