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

@Deepika61 Yes, ideally the payment total should be a sum of the amount field on all associated HR Tasks.

@Sandeep Rajput 

but its not working, its not update anything on the case form once task submitted with amount field value.

@Deepika61 My bad, if the update is taking place at the task level then the business rule should be placed at the task level and not at the case level. Please update Peter's script as follows.

var currentCaseId = current.parent.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.parent.setValue('u_number_of_tasks', numberOfTasks);
current.parent.setValue('u_payment_total', paymentTotal);
current.parent.update();//Update the parent record.

Script Source: @Peter Bodelier 

@Sandeep Rajput 

is that gilding table form the 2nd line is Task or case?

as well 10th line for getting value of task field?

 

 

@Deepika61 GlideRecord would be done on sn_hr_core_task, basically we are fetching all the sibling HR Tasks where the parent is the given HR case. This is done to perform a total of amount and count of tasks.

 

On 10th line,  a sum of all, task amount is done which is correct in my opinion.

 

The BR script shared should run as an After Update business rule on sn_hr_core_task table.

 

Hope this helps.