From 40560c5824e21ba1756a4cc94ceb666ee1732a87 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Wed, 3 May 2023 18:43:44 +0530 Subject: [PATCH] Fix: aggBy.total and aggBy.avg - Fixed: aggBy.total and aggBy.avg to return null when no record has a valid number value --- scripts/logsheet.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/logsheet.js b/scripts/logsheet.js index d1ff713..4e476c3 100644 --- a/scripts/logsheet.js +++ b/scripts/logsheet.js @@ -294,15 +294,19 @@ aggBy.total = function (sheet_id, sheet, attribute) { if (!(sheet_id in floGlobals.appObjects.logSheet.sheetList)) throw ("Sheet not found") - let result = 0; + let result = 0, count = 0; let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[sheet_id].attributes.indexOf(attribute) sheet.forEach(l => { if (!_isNaN(l.log[attrubuteIndex])) { let value = parseFloat(l.log[attrubuteIndex]) result += value; + count++; } }); + if (count == 0) + result = null; + return result; } @@ -318,7 +322,10 @@ count++; } }) - result = result / count; + if (count == 0) + result = null; + else + result = result / count; return result; }