Get the number of problem tasks count present in problem table using GlideAggregate

Shawn33
Tera Expert

Get the number of problem tasks count present in problem table, number should be populate in custom field(number of problem tasks) in problem after inserting new problem task Record.

 

3 REPLIES 3

Dan H
Tera Guru

Hi,

Is that the total number of tasks, or the number of tasks for each problem?

 

If its for the number of tasks for that specific problem:

You need a business rule

 

find_real_file.png

find_real_file.png

 

Script:

(function executeRule(current, previous /*null when async*/) {

	var probTask = new GlideAggregate('problem_task');
	probTask.addQuery('problem', current.sys_id);
	probTask.addAggregate('COUNT');
	probTask.query();
	if(probTask.next()){
		probTask.next();
		current.u_number_of_problem_tasks = probTask.getAggregate('COUNT');
	}
})(current, previous);

 

Hope this helps.

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

Total no.of problem tasks present in each problem record

First script gives total number of problem tasks for that specific problem.

 

This second script gives total number of problem tasks for all records:

(function executeRule(current, previous /*null when async*/) {

	var probTask = new GlideAggregate('problem_task');
	probTask.addAggregate('COUNT');
	probTask.query();
	if(probTask.next()){
		probTask.next();
		current.u_number_of_problem_tasks = probTask.getAggregate('COUNT');
	}
})(current, previous);

 

Hope this helps.

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H