Forum Discussion
christopher_gillis
8 years agoCommunity Manager
Hi Chris,
So there's two ways you can go about this. The easiest way would be to add an onBeforeUpdate server event that calculates the total each time that the item is saved. However, this means that the total you want to calculate won't appear until after the user saves the item.
If you'd prefer the total to be updated dynamically, you could use code like the sample below from an onEditFinish event on the Properties themselves.
Christopher Gillis Aras Labs Software Engineer
// Get the item
var po = this.item.querySelector("#" + relatedID);
// Get the properties from the item
var quantity = parseInt(aras.getItemProperty(po, "quantity"));
var price = parseFloat(aras.getItemProperty(po, "price"));
var ppu = parseFloat(aras.getItemProperty(po, "price_per_unit"));
// make sure we have all the pieces to calculate the total
if (!!quantity && !!price && !!ppu) {
// Calculate the total
var total = quantity * (price / ppu);
// Set the total
aras.setItemProperty(po, "total", total);
// Refresh the form so this new value appears
aras.uiReShowItemEx(this.item.id, this.item);
}
Note that this sample code assumes that these properties are being updated from a relationship grid and not from a Form.
Chris
Christopher Gillis Aras Labs Software Engineer