BPM, Workflow, and Case

 View Only
  • 1.  calculate total for column

    Posted Tue September 27, 2022 07:11 AM
    hello everyone. im struggling with calculating a "total" amount for a table im currently working on. i have a column of products, a second columns which is "max amount to spend" and a third column which represents how much im spending. what im trying to achieve is that on user input  on the thrid column (how much im spending) i need to calculate the sum of all values in the third column and display it on the third column of the last row of the table. i have developed all the logic that calculates the total but im calling it from a function con the "on change" event handler for the input field. the issue im having is when i try to overwrite the "total" value, as its changing the value of an element of the column, it triggers the formula to recalulate infinitely. 


    ------------------------------
    Hernan Gaona
    ------------------------------


  • 2.  RE: calculate total for column

    IBM Champion
    Posted Wed September 28, 2022 07:23 AM
    Hi Hernan,

    I think the approach is incorrect, within the table, the 3rd column is having binding with same variable of different index. I not saying it is a technical challenge but I think you can take a separate section to show the totals.

    If you need to do this in the same table, then write below code in the "On Blur" event of the 3rd column (list1 and spentAmount are the controls ids of the table and the 3rd field respectively) - 
    if((me.ui.getIndex()+1) != view.context.binding.get("value").items.length){
    	var totalAmount = 0;
    	for(var i=0; i<view.context.binding.get("value").items.length-1; i++){
    		totalAmount += view.context.binding.get("value").items[i].spentAmount;
    	}
    	view.ui.get("/list1/spentAmount["+(view.context.binding.get("value").items.length-1)+"]").setData(totalAmount);
    }
    


    Hope this helps.



    ------------------------------
    Atanu Roy
    Solution Architect
    Salient Process
    ------------------------------



  • 3.  RE: calculate total for column

    Posted Wed September 28, 2022 09:30 AM
    Hello, 
    There are also some shorthand notations that might prove useful for situations like this. See https://www.ibm.com/docs/en/baw/20.x?topic=views-formulas

    Stuart...

    ------------------------------
    Stuart Jones Business Automation Technical Specialist
    Business Automation Technical Specialist
    IBM
    Cedar Rapids IA
    630 390 4436
    ------------------------------