How to compute the extra fields?

Hi,
Dolibarr computed fields function looks interesting but i want to know if i create two extra fields, let’s say extra field A and extra field B.
How can i add both and display in extra field C.

Thanks in advance
S

Found it, here is how to do it if it helps anyone.

($object->array_options [‘options_XXX’])+($object->array_options [‘options_XXX’]) Simple addition
($object->array_options [‘options_XXX’])*($object->array_options [‘options_XXX’]) Simple Multiplication
($object->array_options [‘options_XXX’])+($object->array_options [‘options_XXX’]) Simple subtraction

3 Likes

Do you know how to access extra fields from other Modules?
I want to get the content of my own extrafield “Kundenprojektnummer” created in Project module in the facture module

Hi,

This is not easy I would say.

Here you have an example to load an extrafield from societe

(($reloadedobj = new Societe($db)) && ($reloadedobj->fetch($obj->id ? $obj->id : ($obj->rowid ? $obj->rowid : $object->id)) > 0)) ? $reloadedobj->array_options['options_extrafieldkey'] * $reloadedobj->capital / 5 : '-1' 
1 Like

Hi Ksar,
thanks for you fast reply. I found that example too. Because i’m not quite familiar with PHP could you help me? Which of the values do I have to replace? What are the id’s? My extrafield key is “kdnprj” so i Understand that I have to change ‘options_extrafieldkey’ to options_kdnprj. What is the last part of the function doing ```

  • $reloadedobj->capital / 5 : ‘-1’ ?

Thank you for your help!

Hi,

I would say that if you do not have PHP skills it will be difficult.

This is what worked for me:
the field “kdnprj” from module “Projects” will be displayed in an Extrafield in module “Invoice”

(($reloadedobj = new Project($db)) && ($reloadedobj->fetchNoCompute($obj->id ? $obj->id: ($obj->rowid ? $obj->rowid: $object->fk_project)) > 0)) ? $reloadedobj->array_options[options_kdnprj]: $reloadedobj
2 Likes

edit: change

$reloadedobj->array_options[options_kdnprj]: $reloadedobj

to

$reloadedobj->array_options[options_kdnprj]: 'no linked project'

otherwise it won’t work if no project is linked

2 Likes

Hello, if I want to compute Product Stock reel with an extrefield like this:
ExtraField_B = Product_Stock_Reel * ExtraField_A
Does anyone know how to do it?
Thanks in advance!

I don’t know what Product_Stock_reel is, but you can compute extrafields like this:

($object->array_options [options_ExtraField_B])*($object->array_options [options_ExtraField_A]

If you want to multiply given fields and extra fields (for example: ExtraField_A*object_total_ttc):

($object->array_options [options_ExtraField_A])*($object->total_ttc)

Hello Simmer,

Where exactly do you place this code snippet you are mentioning?

@simmer
I used your code and the extrafield work well if I add another extrafield. Now I need to add to my extrafield the number of users insert in the project. Can you help me about the object I need to use for doing this?

Thank you very much