How to limit reference choices based on user info for catalog item

douglaslubetkin
Kilo Explorer

Hello,

I'm configuring a new catalog item and one of the variables that is being requested is a reference field that displays the user submitting the catalog item's team members. My thinking is to use the department field and not an assignment group because it is a one to one relationship instead of a M2M. If there is a better though process I'm open to suggestions. The new reference variable called "reqApprover" should only display the original requester's team members coming off the "employeeId" which is the first field on the catalog item.

Please help

3 REPLIES 3

Chuck Tomasi
Tera Patron

Hi Douglas,



You can certainly build a reference qualifier to do that. Under the Type Specification section, set your filter to advanced. You'll need to write a script to find the sys_ids of the users with the same department (if that's what you are referring to as team members.)



In the Reference qual field you put: javascript:myTeamMembers();



The script then returns an encoded query string like: sys_idINxxxxxxxx,yyyyyyyy,zzzzzzz to act as the filter.



find_real_file.png



See section 4.3 here: Reference Qualifiers - ServiceNow Wiki


Chuck,



Thanks for getting back to me! Do you have an example of what the script would look like? I'm struggling with that part more than the ref qualifier.



Thank you,



Doug


bbarber9
Giga Expert

I have gotten this to work before by using GlideAjax although it doesn't use a exactly use a reference field. Here is how it works:


  1. Create an empty select box to replace your reference field.
  2. Create a GlideAjax Script Include that will query your table and send back both the value you want to display in the dropdown and the sys_id for each result.
  3. Call your GlideAjax from a client script that runs onChange of your department field.
  4. Use the addOption method in g_form to add an option that uses the display value for the label and the sys_id for the value.
  5. When a user selects a department it should load your results. The value of that variable will be the sys_id just like a reference field.