Calculated Custom Field Not working in V19

I just notice that my instance is now in v19 (which by the way I couldn’t find the setting that made it to automatically upgrade to the latest version, I would like to turn that off so that next time I can pick the time I wish to upgrade and perhaps do a backup first before doing so so that I can easily revert back)

Suddenly all my calculated fields are having some problems


Bad string syntax to evaluate (found call of a function or method without using direct name): ((($reloadedobj = new Product($db)) && ($reloadedobj->fetchNoCompute($objectoffield->fk_product) > 0)) ? $reloadedobj->array_options[‘options_pcsperbag’] : ‘0’)

my exact fomrula is:
((($reloadedobj = new Product($db)) && ($reloadedobj->fetchNoCompute($objectoffield->fk_product) > 0)) ? $reloadedobj->array_options[‘options_pcsperbag’] : ‘0’)

it was working fine before and in fact I have another sandbox which is still in v18 with the same formula and have no problems

Can anyone please help?

Hi there,

same issue here since the V19. It is a un-documented regression and I did not find a working fix for now w/o digging to the underlying dolibarr code.

As soon as I had relative complex formula (in my case simply substracting a date custom field with the current date to find an age…) with an if condition (?) it does throw the same error as you have.

After hours of working I finally ended up to remove the if condition (?) and it does work, however with a regression as if the custom date field is not filled in, the end-user will see the current year (a bit ugly).

For info, my formula >>

dol_print_date(dol_now(), ‘Y’) - dol_print_date($object->array_options[‘options_bpdateofbirth’], ‘Y’)

PS : I tried all sort of () to isolate variables, etc w/o success. I had to revert back to this very simple formula…

i did manage to fix my formula.

($reloadedobj = new Product($db)) && ($reloadedobj->fetchNoCompute($objectoffield->fk_product) > 0) ? $reloadedobj->array_options[“options_pcsperbag”] : 0

from
((($reloadedobj = new Product($db)) && ($reloadedobj->fetchNoCompute($objectoffield->fk_product) > 0)) ? $reloadedobj->array_options[‘options_pcsperbag’] : ‘0’)

think it was with the unnecessary parenthesis maybe. not sure, but you can compare the two formulas