I have created two entities, otherIncome and bonus, with a one-to-many relationship between them. I want to calculate the total sum of the amount field in the bonus entity and display it in the number field of the otherIncome entity.
calculate the total sum of the son entity's field
Collapse
X
-
calculate the total sum of the son entity's field
I have created two entities, otherIncome and bonus, with a one-to-many relationship between them. I want to calculate the total sum of the amount field in the bonus entity and display it in the number field of the otherIncome entity.Tags: None -
easy, below the code you need to apply to the otherIncome entity formula:
PHP Code:if (entity\isAttributeChanged('bonusesIds')){ number = entity\sumRelated('bonuses', 'amount'); }
make sure that the names of the relationships are correct i just assumed that one otherIncome has many bonusesRabii
Web Dev -
but is this code will work after deleting or unlinking bonuses?Last edited by zerosix; 01-21-2024, 11:11 PM.Comment
-
hey zerosix
It should work if you have [Link Multiple Field] option enabled on your relationship otherwise it won't work and you will have to amend the code to something like below in order to work on both unlink and remove:
PHP Code:if (entity\countRelated('bonuses')) { number = entity\sumRelated('bonuses', 'amount'); } else { number = null; }
Rabii
Web DevComment
Comment