Hello,
I hope someone can help me. I created a javascript to calculate a column in a subgrid, but it it not working. I will add the javascript code below:
function onLoadCostTable(executionContext){
formContext = executionContext.getFormContext();
gridControl = formContext.getControl("Subgrid_new_6");
gridControl.addOnLoad(myFunction);
}
function myFunction(){
let myGrid = gridControl.getGrid();
var myRows = myGrid.getRows();
var total=0;
LoopedIn = new Boolean(false);
myRows.forEach(function (row, index){
LoopedIn = true;
// get all attributes in a row
var attributes = row.getData().getEntity().attributes;
// get each attribute in a row
attributes.forEach(function (attribute, index){
//console.log("Name:" + attribute.getName() + " , Value:" + attribute.getValue());
//change to your field name
if(attribute.getName() == "hrex2193_cost"){
total += attribute.getValue();
}
})
})
if (LoopedIn) {
formContext.getAttribute("hrex2193_coursetotalcost").setValue(total);
}
}
I registered the function "onLoadCostTable" on the on load of the form, but the rows are returning undefined and the script is not continuing.
The subgrid contains data and the view contains the field that I want to calculate. May someone lead me how to wait for the subgrid to load and then start the calculation?
Thank you!