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:
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
When do you use the above code instead of the "entity\sumRelated" function to re-calculate totalPrice in the Order entity?
Is option to do it using dynamic-handler? https://docs.espocrm.com/development/dynamic-handler/
It work's! Thank You! Is some simple way to see result of calculation "live", before clicking "update"?