Using a Lookup Select Box to Narrow options for Second Lookup Select Box

JamieNow
Tera Contributor

Hello, Developers!

Here's the low down:

  1. I have two lookup select box variables on my catalog item that I want to filter the same table
  2. The first one should filter based on a field we're using as a flag called "type" and it should equal to "category"
  3. The second field should filter the same table with the "type" equal to "topic" AND it should show records from the table that have a "parent" field (reference field for the same table with "name" field as display value) set to the same option selected from the first list select box

Here's what I've tried:

  1. An advanced Reference Qualifier
    • javascript:'parent='+ current.variables.category
    • javascript:'parent='+ current.variables.category.toString()
  2. I tried a script include
    • Code: 
var CategoryReferenceQualifier = Class.create();
CategoryReferenceQualifier.prototype = {
  initialize: function() {},

    getSysIdFromName: function(name) {
      try{
        var categorySysId = '';
        var gr = new GlideRecord('my_custom_table_name'); 
        gr.addQuery('category_name', name);
        gr.query();
        if (gr.next()) {
            categorySysId = gr.sys_id.toString();
        }
        return categorySysId;
       }
       catch (ex) {
         gs.error("Error in getSysIdFromName: " + ex);
         return '';
       }
    },


  getReferenceQualifier: function(type, categoryName) {
      var categorySysId = this.getSysIdFromName(categoryName);
      if (!categorySysId) {
          return '';
      }
      gs.info("Here's the sysID: " + categorySysId);
      gs.info("Here's the type: " + type);
      return 'parent=' + categorySysId + '^type=' + type;
  },

  type: 'CategoryReferenceQualifier'
};
  • Reference Qualifier: javascript: new CategoryReferenceQualifier().getReferenceQualifier(current.Variables.category)

N.B. I  used the .toString() method and the script include just in case the the "parent" reference field I'm trying to filter by needed a sysId as a string. I'm not even sure what the first list selector box data/value would look like. Is there even a way to debug reference qualifiers? I've looked at product documentation and nothing seems to be doing the trick. Please help! 

 

5 REPLIES 5

@JamieNow 

try this ensure the 1st variable has Lookup value field set to SysId

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader