How to set date field runtime based on other field

Goodmorning,
I would like to populate date field, run time based on other field value. I try to explain with an example:
field A --> date field
field B --> field that determine the value for the field A.

When I create a new record, field A, is empty.
After fill field B, if value == 1 --> field A must prepopolate with a date one year afert
if value == 2 --> field A must prepopulate with 2050-12-31

I have a problema cause, a format date user.

Can someone help me?

B

Hi,
you can do date calculations either using custom php code and logic hooks (https://docs.suitecrm.com/developer/logic-hooks/) or by using workflows. Workflows don’t require php-code, but a little pseudo-code that is documented here:

e.g.:
{subtractYears(Y-m-d; 2016-04-22; 5)} returns 2011-04-22

Thank you for your anwser, but I need to do this, runtime. cause user can change the value.

I have 2 problems:

  • First: how can I transform format from yyyy-mm-dd to userformat?

  • Second: if I try to modified value so: $(’#myfield’).val(value_with_userformat) the val in UI doesn’t change. Remain the old value fill first

B