Make a Reference value depend on a List Choice value

Chronos
Tera Contributor

Hi,

I have a table Company(core_company) which has 2 fields Name(name,type : String) and Area(u_area, type : Choice). In Area there are 10 values(or more).
For example, when Area = Russia, there will be 3 Name(A,B,C); Area = Japan will have 3 Name(C,D,E)
I create a custom table called Test, which also has 2 fields, Location(u_choice, type : Choice) and Place (u_place, type : references).

In Location I connect to Choice Table (core_company) of Area and get the choice value of Area.
In Place I refer to the core_company table, and the Place field depends on Location.

I would like that when the value of Location changes, the value of Place( same Name (core_company)) appears only the value that matches Location. Is there a way to do it with Script ?.
Thanks

Chronos_1-1678941121852.png

 

 

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

It can actually be done without code.  I quickly added the new "Area" field on the Company table and created a new "Test" table with both "Location" and "Place" fields like you have.

 

Here are the Companies that have an Area selected:

 

JimCoyne_0-1678948170361.png

And here's the new "Test" table, configured with the "Location" field pointing back to the "Area" choices on the "Company" table:

 

JimCoyne_2-1678948318794.png

 

The trick is to configure the "Place" Reference field with the following setup:

1. set the "Use reference qualifier" field to "Advanced" and the "Reference qual" field to "javascript:'u_area=' + current.u_location" (you might have to switch to the "Advanced" view if not already)

 

JimCoyne_4-1678948538878.png

 

2. add an attribute to the field (at the bottom of the form) which tells the system to send back the value of the "Location" field so it can be used in the Reference Qualifier

 

JimCoyne_5-1678948657827.png

 

So now when you select a Location, only those matching Companies can be selected:

 

JimCoyne_8-1678949223269.png

 

Make sure any field names I am using here match what you actually have in your instance and change accordingly.

View solution in original post

6 REPLIES 6

Hi, @Jim Coyne 

It's working.

Thank you so much.

You are welcome, glad that helped.