How to modify a reference qualifier for a Catalog Item variable?

Bill7
Mega Expert

Currently we use a reference qualifier to determine what fields are available in a reference field. I have not found where I can do the equivalent to an If statement for it.  This filter works for every choice except one choice.  If they pick that choice we do not want to filter at all.  Any idea how to handle this?

 

Current reference qualifier: javascript: 'u_kemper_business_unit=' + current.variables.business_unit_aws+'^environment='+current.variables.environment_ref_aws;

1 ACCEPTED SOLUTION

You can try this as your reference qualifier:

javascript:(function() {  if (current.variables.business_unit_aws == 'DBA-misc') {return;} else { return ('u_kemper_business_unit=' + current.variables.business_unit_aws+'^environment='+current.variables.environment_ref_aws);} })();

By returning nothing for the DBA-misc statement it means we don't have anything for our reference qualifier, which is what you're looking for. 

A Script Include could be used as well. The Script Include would be easer to read (the above is one giant line) and reusable. 

I would probably just do the self-executing function myself if I wasn't needing to reuse it because what you are asking for is pretty straight forward. I would draw the line at having to do a GlideRecord lookup or something more complicated just because it's hard to read the code all on one line.

I have tested the above using other variables on a form in my instance. I have not tested it using current.variables though. I am assuming it would work, but that's the part I'll let you test. If it doesn't we can do it in a Script Include.

View solution in original post

11 REPLIES 11

Mohith Devatte
Tera Sage
Tera Sage

Hello ,

In this case please call a script include in the reference qualifier using the below syntax

javascript:new your_scriptinclude_name().your _function_name(pass your choice value as paramter);

 

and in your script include you can write your code for IF statement and return true or false 

 

Please mark this helpful if this answers your question.

Thanks

Mohith

 

alexaria
Tera Contributor

you can also use a client script if you want to be a bit more dynamic:

this article worked for me:
How to modify Reference Qualifiers with Catalog Client Scripts – ServiceNow – ServiceNow Think (word...

 

 

and this is the onChange client script:

 

var resetFilter = 'active=true^nameISNOTEMPTY^emailISNOTEMPTY^EQ';
var dynamicFilter = g_form.getValue('your other text var holding encoded query').toString().trim();
var gg = g_list.get('your ref var name'); // GlideList2 object
gg.setQuery(newValue == '' ? resetFilter : dynamicFilter);