- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:38 AM
Hello,
I'm trying to calculate the total completed story points within a completed PI. This is what I have, but my logged value is returning zero; I'm aware my return value is empty at the moment. This is also within a PDI.
(function calculatedFieldValue(current) {
var totalStoryPoints = 0;
var grPI = new GlideRecord('sn_safe_program_increment');
// Add a query to find the completed PIs
grPI.addQuery('state', 3);
grPI.query();
// Loop through each completed PI
while (grPI.next()) {
var grStory = new GlideRecord('sn_safe_story');
grStory.addQuery('story_points', grPI.sys_id);
grStory.addQuery('state', 3);
grStory.query();
while (grStory.next()) {
totalStoryPoints += grStory.story_points;
}
}
gs.info('Total completed story points: ' + totalStoryPoints);
return ''; // return the calculated value
})(current);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 01:24 AM
Hi @TerryC03 I see few errors in your script. Correct bold lines as per below
var totalStoryPoints = 0;
var grPI = new GlideRecord('sn_safe_program_increment');
// Add a query to find the completed PIs
grPI.addQuery('state', 3);
grPI.query();
// Loop through each completed PI
while (grPI.next()) {
gs.info("inside while"+grPI.number);
var grStory = new GlideRecord('sn_safe_story');
grStory.addQuery('sn_safe_program_increment', grPI.sys_id); // here you need to check sysid of parent i.e program increment but your passing story_points here which is wrong, once you fix this it should work
grStory.addQuery('state', 3);
grStory.query();
while (grStory.next()) {
totalStoryPoints += grStory.story_points;
}
}
gs.info('Total completed story points: ' + totalStoryPoints);
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:50 AM
Thanks for the response. However, I'm still logging 0. Here's the PI demo data:
I want to get the total amount of completed story points within this completed PI when queried.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 01:11 AM
Can you please answer below questions?
1. please provide the table name , field name of calculated fields
2. table name , field_name from where we need to get total value
3. relationship between above two tables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 01:16 AM
- sn_safe_story, story_points
- sn_safe_program_increment, number
- Program Increment -> SAFe Story [both task table]