How to calculate number of tasks associate with Case and updated on the field?

Deepika61
Tera Contributor

Hi All, 

I have  requirement that, basically we two type of tasks "process payment" and "process for leave",

1.Here we have field" number of tasks" on the case form , its read only, so in that field, we need to populate the sum of all "process payment " tasks associate with the case?

2.And  in HR task we have few fields "amount and date", And in the case  one more field "payment total", in this field(payment total  we need to populate sum of "amount "field value of all "process payment " tasks associated with the case?

 

Please help me to solve this

 

Thanks

Deepika

19 REPLIES 19

Peter Bodelier
Giga Sage

Hi @Deepika61,

Assuming that the trigger for this calculation is a change of the case itself, and you will have to adapt it to your situation:

 

var currentCaseId = current.getUniqueValue()
var taskQuery = new GlideRecord('sn_hr_core_task');
taskQuery.addQuery('parent', currentCaseId);
taskQuery.addQuery('type', 'process payment');
taskQuery.query();

var numberOfTasks = 0;
var paymentTotal = 0;

while (taskQuery.next()) {
  numberOfTasks++;
  paymentTotal + taskQuery.getValue('u_amount');
}
current.setValue('u_number_of_tasks', numberOfTasks);
current.setValue('u_payment_total', paymentTotal);

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Hi @Peter Bodelier 

Thanks for the response,

Actually this After update BR was in Case table on in HR task table?

@Deepika61 The business rule should run on HR Case table.

@Sandeep Rajput 

Thanks for the response

Actually i need that whenever i have updated "amount" field value on task then that value should update on the field "payment total" on the case form?

 

if case have multiple tasks, then 'payment total", should be sum of the "amount field" of the all associated tasks?

 

Thanks Deepika