Page 1 of 1

Dependent lookup field with default value

Posted: 2019-11-13 06:02
by Alisson
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.

Re: Dependent lookup field with default value

Posted: 2019-11-14 16:56
by pbottcher
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.

Re: Dependent lookup field with default value

Posted: 2019-11-29 04:52
by Alisson
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.