Calculated field

Good evening, I know very well that the formula is wrong, due to my ignorance; I wrote it this way, just to know if it is possible to get a conditional calculation and possibly an example on how to write it.
Thank you

if (($object->array_options ['options_misureps1']) = 1 and ($object->array_options ['options_stratigrafia1']) = 1 ) then ($object->array_options ['options_str1a'])-($object->array_options ['options_str1b']);
if (($object->array_options ['options_misureps1']) = 1 and ($object->array_options ['options_stratigrafia1']) = 2 ) then ($object->array_options ['options_str2a'])-($object->array_options ['options_str2b']); 
.......etc...continue n times

Hello,

You should use Ternary : PHP Ternary Operator

if (($object->array_options ['options_misureps1']) = 1 and ($object->array_options ['options_stratigrafia1']) = 1 ) then ($object->array_options ['options_str1a'])-($object->array_options ['options_str1b']);

should become

(($object->array_options ['options_misureps1']) = 1 and ($object->array_options ['options_stratigrafia1']) = 1 )?($object->array_options ['options_str1a'])-($object->array_options ['options_str1b']):'';

Hi Ksar, I tried what you suggested but it doesn’t work, I think it’s a problem in the formula, as the system can no longer open the project page, could it be because some of the fields in the formula may not contain data?

Stephen

Hello,

You have to tell a bit more, how the extrafields are declared etc…
What is you Dolibarr version ?
It’s a line extrafiled or a “normal” one ?

I also correct a bit the equation that was still wrong above :

(($object->array_options['options_misureps1'] == 1) && ($object->array_options['options_stratigrafia1'] == 1))?($object->array_options['options_str1a']-$object->array_options['options_str1b']):'';

Good morning Ksar, you are right; the version used is 16.0.3 the fields are project-extrafields, in practice a field must be calculated based on n combinations between 2 other fields all present in the indicated table.

Stefano