Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to populate options for a field based on the other field's value?

LinhN
Tera Contributor

Hi guys, I am a newbie service now. I have a requirement and want to ask you for help

Requirement: I have 2 variables on a catalog item called variable A and variable B. Variable A is referenced from Table 1 ( Option a, b, c,...),  and variable B is referenced from Table 2 ( option a1, a2, b1, b2, c1, c2,....).  

Challenge:  I want to create a client script to filter options for Variable 2 based on the option that is selected from Variable 1. For example, when users select option a from Variable A, the variable B will filter options a1, a2, a3, .. 

Solution:  How can I use Glide Ajax and Script Include for this requirement? Can you give me a suggestion? Thank you

2 ACCEPTED SOLUTIONS

Abnezer G
Tera Guru

hi @LinhN ,

 

You can use reference quantified in the Secord variable.

 javascript:'field_used_for_filtering=' + current.variables.VARIABLE A 

Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!! 

View solution in original post

Robbie
Kilo Patron
Kilo Patron

Hi @LinhN,

 

This can be easily achieved with the use of an Advanced Reference Qualifier - not client script is required.

The trick is to make sure you have the syntax correct. Check my screen shot and this code:

 

javascript:'group=' + current.variables.ref_1

// for your script you'll need something like:
javascript:'your_variable_a_field_name=' + current.variables.variable_b //where you have variable b, this should be the matching value against your variable a field

 

In the below example, I've got 2 ref fields (Called Ref 1: 'ref_1' and Ref 2: 'ref_2)

Ref 1 is pointing to the 'Group' table (sys_user_group) and Ref 2 is pointing to the Group Member table (sys_user_grmember).

The Group Member are filtered by the Group field.

 

Screenshot 2024-07-29 at 11.04.47.png

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

View solution in original post

5 REPLIES 5

Abnezer G
Tera Guru

hi @LinhN ,

 

You can use reference quantified in the Secord variable.

 javascript:'field_used_for_filtering=' + current.variables.VARIABLE A 

Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!! 

LinhN
Tera Contributor

Oh. The table of variable A ( table 1)  is different from variable B ( table 2). The table for the variable B has a field reference to table 1.  I have used your suggestion but it didn't work. Can you suggest to using Client script

Robbie
Kilo Patron
Kilo Patron

Hi @LinhN,

 

This can be easily achieved with the use of an Advanced Reference Qualifier - not client script is required.

The trick is to make sure you have the syntax correct. Check my screen shot and this code:

 

javascript:'group=' + current.variables.ref_1

// for your script you'll need something like:
javascript:'your_variable_a_field_name=' + current.variables.variable_b //where you have variable b, this should be the matching value against your variable a field

 

In the below example, I've got 2 ref fields (Called Ref 1: 'ref_1' and Ref 2: 'ref_2)

Ref 1 is pointing to the 'Group' table (sys_user_group) and Ref 2 is pointing to the Group Member table (sys_user_grmember).

The Group Member are filtered by the Group field.

 

Screenshot 2024-07-29 at 11.04.47.png

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

LinhN
Tera Contributor

It looks good. I have used your suggestion and it worked. Thank you very much