Page 1 of 1

Change Field Value based upon another value....

Posted: 2024-12-18 02:52
by jonathan.ayres
Good evening all, have an issue that is making me pull my hair out (because I've forgotten how to make it work correctly!).

Have a field called "Oppstatus" that is a drop box with several values. (Open, Quoted, Approved, etc)
Have another field called "Probability" that is a drop box with percentages (0%, 10%, 20%, etc)

Whenever someone selects the value "Quoted", would like the percentage change to 30%, or if changed to "Approved", change to 90% - however, would still like the ability for the operator entering the data to manually override the percentage.

I think jquery is the way to go; but my brain is just not firing on all cylinders...

Re: Change Field Value based upon another value....

Posted: 2024-12-18 16:42
by Marcelo Vitoria
In the table where the "Oppstatus" field is, also insert the percentage field that you need to display.

When the user selects the value Open, Cited, Approved, etc., in the Probability field you configure it as a lookup field with autofill checked to pull the percentage value from the "Oppstatus" table, but this lookup field cannot be edited separately.

I hope this helps.

Re: Change Field Value based upon another value....

Posted: 2024-12-19 18:39
by jonathan.ayres
Marcelo, thanks... That unfortunately doesn't allow the user to "override" the percentage. I built something like this a while back for product additions to quotes; where it would plug in "default" prices based upon the lookup, but would allow the user to override if we had special pricing for a particular reason...

Re: Change Field Value based upon another value....

Posted: 2024-12-19 22:13
by pbottcher
Hi,

it would be good to know what kind of dropdown you have. Is it a lookup, or an option list.
Logically you can register for the on change of the Oppstatus and based on the new fieldvalue you can trigger a change to the Probaility.

Re: Change Field Value based upon another value....

Posted: 2024-12-20 00:59
by jonathan.ayres
The source dropdown is an option list; not a lookup.

Re: Change Field Value based upon another value....

Posted: 2025-01-03 15:00
by pbottcher
Hi,

you may try this code in the hooks/TABLENAME-dv.js

Code: Select all

function switch_probability(prob) {
	$j('#Probabilit').select2().val(prob).trigger('change');
}

$j(function() {
	$j('#Oppstatus').on('change',function(e) {
		val=e.added.id;
		switch (val) {
			case 'Open':
				switch_probability('10%');
			break;
			case 'Approved':
				switch_probability('90%');
			break;
		}
	})
})
Like this the dropdown will adjust to 10% for open and 90% for approved, but remains editable.