Set Value of current record to those of the same assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 08:14 AM - edited 03-07-2024 08:17 AM
Hello,
I'm trying to take a calculated value from the sn_safe_sprint table. I currently have two queries: one for calculation and the other to set the value of the same field to that of similar groups. For example, I have created a field named "Average Completed Points" (u_average_completed_points; integer).
Within the business rule (before), my first query calculates the Average Completed Points value:
// Query the sn_safe_sprint table to get the latest 3 updated sprints
var gr = new GlideRecord('sn_safe_sprint');
gr.addQuery('state', 3);
gr.addQuery('assignment_group', current.assignment_group);
gr.orderByDesc('sys_updated_on');
gr.setLimit(3);
gr.query();
//variable to store the total completed points
var totalCompletedPoints = 0;
var count = 0;
// Loop through the records and calculate the total completed points
while (gr.next()) {
gs.info("act "+gr.getValue('actual_points') +" " +gr.getValue('assignment_group'));
totalCompletedPoints += parseInt(gr.getValue('actual_points'));
count++;
}
current.u_average_completed_points = totalCompletedPoints/count;
gs.info("avg "+current.u_average_completed_points);
For this example, the average field calculates to 9 (shown in picture as well). Next, I have another query to take the value of 9 and set the value to all records with the same SAFe Team.
In this picture the average completed points is 9 for SAFe Team "Employee Portal Features Team", I would like to set that value of 9 for all records with the same team. However, my code is not working. Here is what I have:
var grTeam = new GlideRecord('sn_safe_sprint');
grTeam.addQuery('state', 3);
grTeam.addQuery('assignment_group', current.assignment_group);
grTeam.query();
while(grTeam.next()){
gs.info("Team "+current.assignment_group);
grTeam.u_average_completed_points = totalCompletedPoints/count;
}
Any advice would be helpful. I tried grTeam.setValue(), but that did not work. Full code:
(function executeRule(current, previous /*null when async*/) {
// Query the sn_safe_sprint table to get the latest 3 updated sprints
var gr = new GlideRecord('sn_safe_sprint');
gr.addQuery('state', 3);
gr.addQuery('assignment_group', current.assignment_group);
gr.orderByDesc('sys_updated_on');
gr.setLimit(3);
gr.query();
//variable to store the total completed points
var totalCompletedPoints = 0;
var count = 0;
// Loop through the records and calculate the total completed points
while (gr.next()) {
gs.info("act "+gr.getValue('actual_points') +" " +gr.getValue('assignment_group'));
totalCompletedPoints += parseInt(gr.getValue('actual_points'));
count++;
}
current.u_average_completed_points = totalCompletedPoints/count;
gs.info("avg "+current.u_average_completed_points);
var grTeam = new GlideRecord('sn_safe_sprint');
grTeam.addQuery('state', 3);
grTeam.addQuery('assignment_group', current.assignment_group);
grTeam.query();
while(grTeam.next()){
gs.info("Team "+current.assignment_group);
grTeam.u_average_completed_points = totalCompletedPoints/count;
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 08:55 AM
Hi,
What type of field you are trying to set? If it's string, try toString() function. Also, could you please try debugging by log and check if the variables has the correct values or not.
Kindly mark my answer as Correct and helpful based on the Impact.
Regards,
Alok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 09:00 AM
I'm trying to set, for example, the value of 9 from the current record Average Completed Points to the field Average Completed Points to those with the same SAFe Team. Set all similar teams with the calculated value of the current average completed points to their average completed points field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 09:14 AM
I understand that you are facing issue while setting the value in the field.
You are trying to set the field "u_average_completed_points" which is integer type, it will not accept the values in decimal. Try some combination where calculation will return integer value, it will work.
Regards,
Alok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 09:27 AM
It's not returning a decimal (float), it's rounding up to the nearest integer. I removed the fraction as well, but it did not work.