What is the proper way to set a reference qualifier on a list dynamically based on the values of two other fields on a form?

bcronrath
Kilo Guru

Hello all,

I am just hoping for some guidance on how I might accomplish this desired goal:


-I have a field let's call "Services" that is a list type that references table "Services" on my incident form.

-On the Services table exists a Name, Region, and Classification field.   Region and Classifications are also List type fields that reference tables "Region" and "Classifications".   Essentially you can select 1 to many Regions and 1 to many Classifications per Service.

-On my incident form, I have UI policies such that "Region" must be set on it before "Classification" shows up, and then "Classification" must show up before "Services" shows up.

-For the "Services" list on this incident form, I want to filter it down to only allow you to search on Services that have the Region and Classification attached to them.

Dependent field doesn't work because it only allows for 1 field, and even then it only seems to match on a "equals" comparison where I am looking to do a "like" comparison.

I assume a Dynamic ref qual is what I need to use here, although I am looking for a bit of guidance on how I am suppose to accomplish this?   Do I need to somehow integrate a client script so that I can use the g_form.getValue() functionality?   This is essentially the issue I am not very clear on - how do I grab values from the form to use within a reference qualifier (or otherwise filter for the "Services" list).   Is it even possible?

Best regards,

Brian

1 ACCEPTED SOLUTION

JohnG3
Mega Guru

Hi Brian,



You may want to try an Advanced Reference Qualifier: Reference Qualifiers - ServiceNow Wiki



Some pseudocode for a Script Include to use in the Advanced Reference Qualifier as javascript:new servicesbyRegionClassification().servicesbyRegionClassification()



var servicesbyRegionClassification = Class.create();


servicesbyRegionClassification.prototype = {


  initialize: function() {


  },



  servicesbyRegionClassification:function() {


  // Region from the Incident


  var region = current.u_region;


  // Classification from the Incident


  var classification = current.u_classification;



  // Reference Qualifier for the Services


  return 'u_regionLIKE' + region + "^" + "u_classificationLIKE" + classification;


  },


  type: 'servicesbyRegionClassification'


}


View solution in original post

6 REPLIES 6

JohnG3
Mega Guru

Hi Brian,



You may want to try an Advanced Reference Qualifier: Reference Qualifiers - ServiceNow Wiki



Some pseudocode for a Script Include to use in the Advanced Reference Qualifier as javascript:new servicesbyRegionClassification().servicesbyRegionClassification()



var servicesbyRegionClassification = Class.create();


servicesbyRegionClassification.prototype = {


  initialize: function() {


  },



  servicesbyRegionClassification:function() {


  // Region from the Incident


  var region = current.u_region;


  // Classification from the Incident


  var classification = current.u_classification;



  // Reference Qualifier for the Services


  return 'u_regionLIKE' + region + "^" + "u_classificationLIKE" + classification;


  },


  type: 'servicesbyRegionClassification'


}


Sweet!   Thank you John I didn't realize that "current" in this context would pick up the changes on the form but it appears that it does.   This is working for me, I have to flesh it out a bit to account for the many to many comparison but once I get it all working I will update w/ the code unless anyone needs to do something similar.



-Brian


Hi Brian C,



Yeah, a unique scoping situation for "current" object in reference qualifiers (not well documented in my opinion). Fortunately, the Script Include provides the flexibility to account for the more complex comparisons and logical conditioning.



Thanks for sharing your final code when you have it completed for the benefit of our Community.



~ John G


Brian Dailey1
Kilo Sage

Hi Brian,



You can enter an advanced reference qualifier directly in the Reference Qualifier field:



      javascript:"u_regionLIKE" + current.u_region + "^u_classificationLIKE" + current.u_classification;



I've made the assumptions that 'region' and 'classification' are both custom fields on both tables (services and incident), thus the "u_" prefix.   This example also assumes that they are not references.   If they are references, include 'sys_id' when referring to them from current (e.g., "current.u_region.sys_id").




Thanks,


-Brian