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 am not sure, I am understanding the architecture correctly or not.


The BR that i have shown just runs on any change on Actual cost field on the Ledger Cost table (tab in the screenshot)


In condition, put current.u_actual_cost.changes()



The above should ideally run whether the update is coming from calculated operation or manual operation.


Not sure what i'm missing here but it is still not updating the actual amount of the form when actual cost changes


find_real_file.png


Hi Chris,



On going through your code, I have few questions -


Isn't the architecture is like


There is Intercompany work order which has many Work order cost records


The sum of these Work Order Cost records should get updated in Intercompany work order



I assume the Intercompany work order is in Task table (by seeing the task number TASK0020199 in the screenshot)


Work Order cost records sits in another table and this table will have reference to Task table - thats how each Work order cost is mapped to Intercompany work order


I am assuming like there is a Contract and in this contract there are different costs (like steel cost, transport cost, labor cost etc.)


Contract sits in One table in Table A


Steel , Transport , Labor costs sits in Table   B and table B has reference to Table A (the link)


The sum of costs in the Table B for the Contract will add up and shows as Total cost of contract in Table A



This is my understanding of architecture


In view of this, the BR should be written on Table B (i.e work order cost table)


Any addition of costs in work order cost table will add up to the parent table (i.e Table A)


Write an after BR on Table B (work order cost table)


Insert, Update, Delete checked


Condition: current.u_actual_cost.changes()



var amt = 0;


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


        amt = current.u_actual_cost;



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


      amt = -previous.u_actual_cost;



var grTask = new GlideRecord('task'); //querying the parent table i.e in our example the task table


if(grTask.get(current.order_task)){ //this field should hold the task sys_id to which these work order cost refers


        grTask.u_actual_cost = grTask.u_actual_cost + amt; //if the operation is delete, then it will subtract the previous cost, if it is update or insert, its just puts the value


      grTask.update();


}



in your code, in the if clause, you have written .changes() which can be tested in condition field of business rule itself


I hope i understood your architecutre, hopefully it helps


Not sure what I missing now, actual_cost is the field on the related table and actual_spend_amount is the total that needs to update when actual_cost changes which is a calculate value.



find_real_file.pngfind_real_file.png


pasted it twice by mistake