Calculate and populate a field on story form based on scrum tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2022 11:49 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2022 01:53 AM
I changed the field to type- integer. then it works. but for string field it doesnt.
BR- after,insert,update. table-rm_scrum_task
Below is the 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.u_loe = parseInt(hours);
storyRec.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2022 02:02 AM
Hi,
why to keep it as string?
Ensure you keep it as Integer for better reporting and to avoid any garbage value
Please mark my response as correct and helpful to close the thread.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2022 02:45 AM
Can we implement this using roll up field functionality?
Also, initially when the story form loads without scrum tasks or while creating new story, the value in efforts field should be 0.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2022 01:18 AM
Hi,
you can default it with 0 so it sets as 0 during the creation
Then the other logic of calculating will work.
Please mark my response as correct and helpful to close the thread.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 09:26 AM
@Rose
Hope you are doing good.
Did my reply answer your question?
Would you mind marking the best matching answer as correct and helpful, to close this thread so that it benefits future members?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader