Is there a way to use a Dictionary Entry Calculated value to total a related list

Christopher Dan
Kilo Contributor

I have a related list on a form that I need a currency column to total up to a field on the form. I want to use a Dictionary Entry Calculate Value to total so it totals instantly without an update to the record of the related list. Is this possible?

21 REPLIES 21

I updated your script with log statements, please run this and go to log table and put source = debugCostOrder


Please verify whether the log statements are printing -



function onBefore(current,previous){


  var amt = 0;


  if (current.operation() == "insert" || current.operation() == "update")


          amt = current.actual_cost;


   


  if(current.operation() == "delete")


        amt = -previous.actual_cost;



  gs.log("Actual Cost Amount: " + amt, 'debugCostOrder');


   


  var grTask = new GlideRecord('task');


  if(grTask.get(current.work_order)){


            gs.log('Task Number: ' + grTask.number, 'debugCostOrder');


            gs.log('Task Amount before update: ' + grTask.actual_spend_amount, 'debugCostOrder');


            grTask.actual_spend_amount = grTask.actual_spend_amount + amt;


            grTask.update();


  }


}






Hopefully it helps


So the script says update or insert in it when there is never and update or insert. the Actual Cost field for that ledger is on the Work order cost table and is a Dictionay Calculate Field that pulls the total from a field on the main form which is called labor costs. The labor costs gets its total from the calculation total of the time card entries on the form. So   I think maybe an onChange client script would work the way I need it to? Does that help describe the configuration better?


The thing with the calculated field is, it is not onChange field, the value in the calculated field will get reflected after saving the record only.


So from your observation, it seems the business rule is not triggering in the first place, even though the Actual Cost Amount got updated but as it is calculated from multiple values, the BR didnt get trigger?


correct it does not get triggered until I actually go in the record and select Update


And I ran the BR and nothing showed in the log until I selected update on the actual form. So that why I think an onchange is needed because I need it to update automatically.