Dynamic Location Filtering in Catalog Item based on Requestor, Role, and Stockroom (cmn_location)

LavanyaB8479798
Tera Contributor

Hi All,

I am working on a ServiceNow catalog requirement where I need to dynamically filter a Location reference field based on multiple conditions like user role, requestor, hierarchy, and stockroom availability.


Scenario:

I have a Catalog Item with two Variable Sets:

  1. Variable Set 1

    • Field: Requestor For (Reference → sys_user)

  2. Variable Set 2

    • Field: Location (Reference → cmn_location)


🔹 Location Table Structure (cmn_location):

The hierarchy is as follows:

  • Region (e.g., APAC) → top level (parent is empty)

  • Country (e.g., India) → child of Region


🔹 Conditions:

I need to filter the Location field based on:

  1. Location attributes:

    • cmn_location_source = xxxxx

    • cmn_location_type = xxxx

  2. Stockroom condition:

    • Only locations that have a related record in alm_stockroom (i.e., location has a stockroom)

  3. User role:

    • If user has itil role → show Region level (APAC)

    • If user is end user → show Country level (India)

  4. Requestor-based filtering:

    • Based on selected Requestor For, restrict locations within the same hierarchy


🔹 What I Have Tried:

  • Created a Script Include (GlideAjax) to build dynamic query

  • Used Catalog Client Script (onChange) on Requestor For

  • Applied g_form.setReferenceQualifier() on Location field


🔹 Issue:

Since Requestor For and Location are in different variable sets,
I am unsure about the best approach to:

  • Trigger filtering correctly

  • Apply dynamic reference qualifier

  • Ensure it works across multiple catalog items


🔹 Questions:

  1. What is the best practice to handle filtering when variables are in different variable sets?

  2. Is GlideAjax + onChange the right approach, or can this be achieved using a reference qualifier?

  3. What is the optimal way to filter locations based on:

    • hierarchy (parent / parent.parent)

    • stockroom availability (alm_stockroom)

  4. How to make this reusable across multiple catalog items?


🔹 Any suggestions or best practices would be greatly appreciated.

Thanks in advance!