Choice field with dependent field refering to the reference table field not working

snehapatel
Tera Contributor

Hi,

 

I have defined a custom table which includes following 2 fields among others:

 

Field 1 -> reference to sys_user_group

Field 2 -> Choice field with dependent field as Field 1.name (i.e. referring to sys_user_group.name)

 

The requirement is whenever on Field 1, Group 1 is chosen, the choice field should display certain set of values and when Group 2 is chosen another set of values should be displayed. My choice values are defined against the sys_user_group.name values which is the dependent field.

 

In the form, whenever I chose a value for Field 1, the choice field field does not show any values. It looks like the matching of the choice values happens against the sysid of sys_user_group and not against the <name> of sys_user_group. 

 

How to make this work. Please help

1 ACCEPTED SOLUTION

Hi @snehapatel 

 

1) 

  • Create a new field (let’s call it group_name), type String, on your custom table.
  • Mark it as calculated.
  • In the dictionary record, add the calculation, something like:

// Assuming 'u_group' is your reference field to sys_user_group
if (u_group)
answer = u_group.name;
else
answer = '';

 

  • Now, in your choice field dictionary entry, set the Dependent field = group_name.
  • Define your choice dependencies against group_name values (the human-friendly group names).

2)

  • You’d need to ensure groups are moved via update sets so they keep the same sys_id in all environments.
  • This is fragile and not recommended — especially since sys_user_group often contains environment-specific groups.
  • That’s why using names (via calculated field) or a custom mapping table is a safer and more portable approach.

 

View solution in original post

13 REPLIES 13

Mark Manders
Mega Patron

Why not just add the sys id of the group? That's the value you are entering in the field, technically. Otherwise you will need to call to the server to get the name client side and have your choices act on that. Using the sysID is a quicker solution than adding this into a client scrip/ajax call. Your form simply doesn't know the name.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

The sysid would vary from one environment to other.  How would the entire thing be managed when the configurations would be moved from one environment to the other (like dev to test to prod)

Rafael Batistot
Tera Sage

Hi @snehapatel 

 

You cannot directly make a choice list dependent on the name (display value) of a reference field. Instead, you have two main options:

 

  1. Make the dependency on Field 1 itself (the reference field).
    • In your choice list configuration, set the Dependent field to your reference field (Field 1).
    • Enter the sys_id of the group in the dependent value for each choice option.
    • This way, the match will succeed because the choice is compared against the stored sys_id.
  2. Alternative approach (if sys_ids are not manageable)
    • Add a Dictionary attribute or a calculated field that stores the name of the selected group from the reference.
    • Use that field as the dependent field for your choices.

 

But the simplest and recommended way is Option 1: configure the choice list dependency using the sys_id values of the sys_user_group records

@Rafael Batistot ,

 

Thanks for your response . Name is not the display value, it is rather another field of the referenced table. Moreover, when you define the dependent field, it allows you to expand the referenced table and select the field. I would like to further understand, when the system is allowing you to choose the field from the referenced table, why the match always happens against the sys_id.

 

Thanks,

Sneha