Skip to content Skip to footer

Form script to calculate widget values from the child form

Description:

Form script to calculate the child record widget values from the child record. In the below form script two forms are considered first is “raise purchase order” form and second is “asset part details” form which is child form.
The case was to calculate the sum of all submitted “Toal amount” values from child form into the “raise purchase order” form in the “total amount” widget.

Raise PO form

  function val(ws, identifier) {
      return ws.getWidgetValue(identifier);
  }

function isVisible(ws,identifier){
      return ws.isWidgetVisible(identifier);
  }


function onPurchasePriceChange(ws) {
}


function setTotalAmount(ws){
  if (isVisible(ws,"Asset_Part")){
    var childs = val(ws,'Asset_Part');
      if(childs!=''){
        childs = JSON.parse(childs);
        total = 0;

        for(i=0;i<childs.length;++i){
            var child = childs[i];
            var price = parseFloat(ws.getFormObjectWidgetValue(child["foid"],'Total_Amount_3'));

            if (price){
              total += price;              
            }
    
        }
        ws.setWidgetValue("Total_Amount", total);
      }
    } 
}


function onAssetPartChange(ws) {
  setTotalAmount(ws);
    
}

function on_submit(ws){
  setTotalAmount(ws);
}

Was This Article Helpful?

0
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published. Required fields are marked *

Close Bitnami banner
Bitnami