The CreatorCon Call for Content is officially open! Get started here.

How to get the values filtered for Reference variable based on the other variable value

harinya
Tera Contributor

HI 
I have 2 variables in catalog form, employee type and manager
Employee type is choice field have 2 values(Temporary, permanent) 
Manager field is Reference of user table
Below is my Requirement,
If user selects Employee type is Temporary then Manager field should show values active users
If user selects Employee type is permanent then Manager field should show values active users and Employee number is not empty
Can some one please help
Thanks in Advance

1 ACCEPTED SOLUTION

In general, your approach is correct. However, it can be simplified and thus optimized for better performance. There is no need to loop through the list of users, collect their sys_ids and return a "sys_idIN..." encoded query. Instead, you should simply return either "active=true" or "active=true^employee_numberISNOTEMPTY" depending on the selected type. In fact, this can be done directly inside the reference qualifier field with just a single line of code:

javascript: var ref_qual = 'active=true'; if (current.variables.user_type == 'permanent') ref_qual += '^employee_numberISNOTEMPTY'; ref_qual;

 

View solution in original post

3 REPLIES 3

Zach Koch
Giga Sage

So this is a multi step process. First, you'll need a Script Include, then you'll need to set your reference qualifier to Advanced and call your script include. We will break down each step below.

Here is the example script include I created

ZachKoch_0-1718815958503.png

You'll need to change out the values in the script to match your Employee Type values.

As for the record configuration, here is my example that calls the Script Include above

ZachKoch_1-1718816053182.png

You'll need to change the values to match yourScriptIncludeName().yourMethodInTheScriptInclude(current.variables.yourFieldEmployeeType);

Here is the results from my example

Results in Manager when Employee type is Temporary (for context I only have 1 user record with an employee number who is active, so this returns all Active users except for one)

ZachKoch_2-1718816223061.png

Here is the result with Permanent selected (returns the 1 user who has an employee number and is active)

ZachKoch_3-1718816307510.png

 

 

Let me know if you run into issues and I can try to talk you through it.

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

In general, your approach is correct. However, it can be simplified and thus optimized for better performance. There is no need to loop through the list of users, collect their sys_ids and return a "sys_idIN..." encoded query. Instead, you should simply return either "active=true" or "active=true^employee_numberISNOTEMPTY" depending on the selected type. In fact, this can be done directly inside the reference qualifier field with just a single line of code:

javascript: var ref_qual = 'active=true'; if (current.variables.user_type == 'permanent') ref_qual += '^employee_numberISNOTEMPTY'; ref_qual;

 

Thanks for your Response