Dependent lookup field with default value

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
Alisson
Veteran Member
Posts: 81
Joined: 2017-02-25 20:32

Dependent lookup field with default value

Post by Alisson » 2019-11-13 06:02

Hello guys,

I have a question about the lookup fields, let me try to explain:

Two lookup fields: DEPARTMENT and SERVICE.
DEPARTMENT has two options Sales, Photos
SERVICE has 10 options Item1,Item2..., Five items are for SALES and 5 for Photos

SERVICE is filtered by DEPARTMENT, so
if I choose Sales in the first lookup field (DEPARTMENT) the second lookup field (SERVICE) will show only the 5 items for Sales,
if I choose Photos in the first lookup field (DEPARTMENT) the second lookup field (SERVICE) will show only the 5 items for Photos.

I have set the default field to Sales, so when I'm adding a new record the first lookup field (DEPARTMENT) shows Sales automatically.
This works fine, my problem is that the second lookup field (SERVICE) show all the 10 items, unless I click in DEPARTMENT and choose Sales again.
So when adding a new record with a default value in the first lookup field does not work without selecting the same value again. Any workaround for that?

Thank you.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Dependent lookup field with default value

Post by pbottcher » 2019-11-14 16:56

Hi,

You can try this by adding the following to your hooks/TABLENAME-dv.js file:

Code: Select all

$j(function(){
	if (AppGini.current_f1.value == "") { 
		AppGini.current_DEPARTMENT.value="Sales";
	}
});
Assuming the your fieldname is DEPARTMENT and the default value is Sales.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Alisson
Veteran Member
Posts: 81
Joined: 2017-02-25 20:32

Re: Dependent lookup field with default value

Post by Alisson » 2019-11-29 04:52

Hi pböttcher,

That work very well, I've been struggling with this for a long time.
Thank you very much. :D :D

PS. I just have to change "SALES" to "1" as it is a lookup field.

Post Reply