Sum catalog task variable

Jose MMR
Tera Guru

Hi all,

 

I am working on a catalog item with several tasks. These task have a variable with a percent number filled by technician and I want to calculate the total percent for RITM using the partial percent in each task.

 

Could it be possible?

 

I am trying to get the SUM of tha variables from each task and I can not achieve it.

 

Regards.

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Jose MMR You can choose to write a business rule script to update the total on RITM whenever a task is closed by the technician. The script will calculate the sum of variable values on all the closed task and update the total on RITM. 

 

Hope this helps.

Aranya
Tera Guru

Hi Jose,
Do you want the field on the RITM to reflect the sum of the variables as soon as they are updated on the task? If that is the case you can write an After Update Business Rule on the task table and from there access the RITM field and update it with the calculated value.
You can access the task variable using current.variable,field_name in the business rule. Also when you are calculating the sum do not forget to check the type of the input. If the type of the input is an object you can convert it into a string using toString() and then pass it into the parseInt method which would convert the string into a number. 

The basic script can look something like this:

var sum = 0;

	var tasks = new GlideRecord('sc_task');
	tasks.addQuery('request_item',current.request_item);
	tasks.query();
	while(tasks.next()){
		sum = sum + parseInt(tasks.variables.percent.toString());
		
	}
	//now display the value of the "sum" variable in whichever field of the requested item you want