Calculate and populate a field on story form based on scrum tasks

Rose17
Tera Contributor

Hi all,

The requirement is- I have a field named as 'Efforts' on story form.

I want to calculate the sum of actual hours of all scrum tasks for a story record and populate the calculated value in 'Efforts' field.

For eg- if i have 3 scrum tasks- A,B,C for a story record-'test' having actual hours as 2,4,6. I want to calculate the sum of actual hours of all three scrum tasks(A+B+C i.e 2+4+6=12) and populate calculated value(12) in 'Efforts' field of story- test.

Could someone help me to achieve this?

Thanks in advance

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So you will have to iterate all scrum task for the current story and then add up the hours

When do you wish to populate it?

Example script

var hours = 0;
var gr = new GlideRecord("rm_scrum_task");
gr.addQuery("story.number", "STRY0000001");
gr.query();
while(gr.next()) {
	hours = hours + gr.hours;
}

// now you can set the total hours

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I wish to populate it when someone updates or adds a value in actual hours in a scrum task.

I want to implement this dynamically.

then create after update BR on scrum task table

Condition: Story is not empty AND Actual hours change

Script:

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

	// Add your code here
	var hours = 0;
	var gr = new GlideRecord("rm_scrum_task");
	gr.addQuery("story", current.story);
	gr.query();
	while(gr.next()) {
		hours = hours + gr.hours;
	}

	var storyRec = current.story.getRefRecord();
	storyRec.effort = hours;
	storyRec.update();	

})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

decimal value(for eg- 19.0) is populating in efforts field. I expect 19 value to be populated. Can we do that?