Cascade dependency field

Jean Ferreira
Giga Guru

I have a form with 3 reference fields, referring the same table.

Level 1, Level 2, and Level 3.


The referenced table is called Level and it is organized like:
Description, Level 1, Level 2.

When Level 1 is empty, I understand the record is Level 1.
When Level 1 is not empty, and Level 2 is empty, I understand the record is Level 2.
When Level 1 and Level 2 are not empty, I understand the record is Level 3.

Example:

DescriptionLevel 1Level 2
1emptyempty
2emptyempty
1.11empty
1.21empty
1.1.111.1
2.12empty
2.22empty
1.1.211.1
2.2.122.2

 

In the form, I have something like this...

Category:
Level_1: (Reference of Level table)
Level_2: (Reference of Level table)
Level_3: (Reference of Level table)

What I want is:
When I select 1 as Level_1, in the field Level_2 appear only 1.1 and 1.2
When I select 1.1 as Level_1, in the field Level_3 appear only 1.1.1

For that I made Level_1 as dependent field of Level_2, and Level_2 as dependent field of Level_3.

The problem is that Level_3 is returning no values.
For Level_2 is working fine.

 

Screenshot 2023-12-19 at 09.25.45.png

 

Screenshot 2023-12-19 at 09.24.57.png

1 ACCEPTED SOLUTION

Jean Ferreira
Giga Guru

I could solve this problem using reference qualifier in the reference field.

 

Screenshot 2023-12-20 at 09.26.54.png

 

View solution in original post

3 REPLIES 3

Alp Utku
Mega Sage

Can you create an onChange Client on Level 2 variable something like below?

 

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	g_form.clearOptions(level_3_field');

	
	var gp = new GlideRecord('custom_table_name');

	gp.addQuery('variable_2_name_on_the_custom_table',newValue); 

	
	gp.query(function(gp) {

		while(gp.next())
			g_form.addOption('variable_level_3_on_the_form,gp.variable_3_name_on_the_custom_table,gp.variable_3_name_on_the_custom_table);
	});
}

Thanks Alp Utku.

I tried this approach, but did not work well.

When I save the record, it does not match the existent value in the record, so every time I load the form seems like the value is empty.

 

I tried an onLoad Client Script but also did not work.

Jean Ferreira
Giga Guru

I could solve this problem using reference qualifier in the reference field.

 

Screenshot 2023-12-20 at 09.26.54.png