top of page

Total quantity field calculation

Updated: Dec 14, 2021

Many clients asked me this question:

How can I calculate the total quantity from child entity's quantity field

I am going to write the formula based on this structure:


ree

This is the formula:


// Calculate the line "Total Price"
totalPrice = quantity * unitPrice;

// Calculate the parent order "Total Price"
ifThen(
    entity\isAttributeChanged('totalPrice'),
    
    $priceDiff= totalPrice - entity\attributeFetched('totalPrice');

    record\update(
        'Order', orderId,
        'totalPrice', order.totalPrice + $priceDiff
    );
);

Tell me in comments if this was helpful or if any question or suggesion

 
 
 

8 comentarios


Miembro desconocido
13 dic 2021

When do you use the above code instead of the "entity\sumRelated" function to re-calculate totalPrice in the Order entity?

Me gusta
Miembro desconocido
16 dic 2021
Contestando a

Thanks for your reply. I am trying to understand your workaround.

I see that you have a price difference field to use for the comparison, but trying to understand why that is required. Also, you have two "totalPrice" fields in different tables, which adds to my confusion. 🤔

Me gusta

lukasz.serafin
12 may 2021

Is option to do it using dynamic-handler? https://docs.espocrm.com/development/dynamic-handler/

Me gusta
Miembro desconocido
14 dic 2021
Contestando a

Sorry but question is not clear enough

Me gusta

lukasz.serafin
10 may 2021

It work's! Thank You! Is some simple way to see result of calculation "live", before clicking "update"?

Me gusta
Miembro desconocido
14 dic 2021
Contestando a

You are welcome,

To have live sum result will need custom view and some js code

Me gusta

©2020 by Eblasoft.

bottom of page