// 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
// get item ID
var po_pos_id = this.item.querySelector("#" + relatedID);
// get item properties
var po_pos_quantity = parseFloat(aras.getItemProperty(po_pos_id, "pr_pos_quantity"));
var po_pos_price = parseFloat(aras.getItemProperty(po_pos_id, "pr_pos_price"));
var po_pos_ppu = parseFloat(aras.getItemProperty(po_pos_id, "pr_po_priceper"));
// make sure we have all the pieces to calculate the total
if (po_pos_quantity !== 0 && !=isNaN(po_pos_quantity) && po_pos_price !== 0 && !=isNaN(po_pos_price) && po_pos_ppu !== 0 && !=isNaN(po_pos_ppu)) {
// Calculate the total
var total = po_pos_quantity * (po_pos_price / po_pos_ppu);
// Set the total
aras.setItemProperty(po_pos_id, "pr_pos_value", total);
// Refresh the form so this new value appears
aras.uiReShowItemEx(this.item.id, this.item);
}
When I added the code to the property event I couldn't use the input grid anymore. Whenever I tried to jump from one field to another the form seemed busy and didn't allow me to change the information once something was entered, mostly 'NaN' for number fields.
I have an item type called purchase_order. This item contains a related item type called po_lines which should contain single items with a description, quantity and so on. Therefore I think your suggested solution should work as this is in a relationship grid, shouldn't it?
I'm doing something wrong, but I have no idea what it is.
Chris