Getting Sums from related List view

Hello @Jamal_Smith-Graham !

To calculate the sum and show it in the form is the only option to display the total by the column.

To do so, please use the code below. Also, you can disable the Total field so a user will not set it manually.

Please do the following changes in the code:

  • Replace {SPDataTable0} with the List or Library Control internal Name.

  • Change Value in the code (in places like value[i].Value and value[i].Value.replace(/$/g,'')) with the InternalName of the Total Sale Price column. You can check the InternalName in the designer, if you open the child form:

     function calcTotal() {
    
    var value = fd.control('{SPDataTable0}').widget.dataItems();
    var total = 0;
    if(value){
        for (var i = 0; i < value.length; i++){
            if(value[i].Value)
              total += parseInt(value[i].Value.replace(/[^0-9.]/g, ""));
        }
    }
    fd.field('Total').value = total;
    }
    var myVar = 0;
    
    fd.spRendered(function() {
    
    // disable the field
    fd.field('Total').disabled = true;
    
    //refreshing the  total
    var myVar = setInterval(calcTotal, 2000);
    
    }); 
    
    fd.spBeforeSave(function(spForm) {
        var myVar = setInterval(calcTotal, 2000);
        calcTotal();
        clearInterval(myVar);
    });
2 Likes