The Apps Script function being discussed:
function insertNewRow() {
var ss = SpreadsheetApp.openById("redactedforprivacy");
var sheet = ss.getSheetByName("Main");
sheet.insertRowBefore(2);
var date = new Date();
var month = date.getMonth() + 1;
var day = date.getDate();
var year = date.getFullYear().toString().substr(-2);
var formattedDate = month + "/" + day + "/" + year;
sheet.getRange("A2").setValue(formattedDate);
sheet.getRange("C2").setFormula("=ADD(C3,B2)");
sheet.getRange("G2").setFormula("=IF(E2+F2>59,INT((E2+F2)/60)&IF(INT((E2+F2)/60)=1," hour"," hours")&" and "&MOD(E2+F2,60)&IF(MOD(E2+F2,60)=1," minute"," minutes"),MOD(E2+F2,60)&IF(MOD(E2+F2,60)=1," minute"," minutes"));
}
This function creates a new row in the spreadsheet and populates it with useful values and formulas in different cells.
The error message states:
SyntaxError: missing ) after argument list line: 14 file: new line.gs
The main issue is on line 14 where the formula for cell G2
is set. Although the formula may be complex, it functions correctly within the spreadsheet. The error only arises when line 14 exists, but it's important to resolve this without giving up on the formula itself.
Attempts at Resolution:
(Disclaimer: I am not proficient in programming.)
I made several adjustments to the formula by editing, shortening, and altering its structure, yet none of these changes maintained functionality in the spreadsheet; likely due to my own limitations.
I meticulously reviewed line 14 multiple times in search of any missing parentheses, but have been unable to pinpoint the exact issue.
Update: Additional Insights
A suggestion from Tanaike resolved the error in the function execution, however, it induced a parsing error within the formula itself.
Further clarification on the intended purpose of the formula:
This formula is designed to sum the durations in two cells represented in minutes, and then format the outcome into a string showing the combined time in hours and minutes. It incorporates IF statements to evaluate if the total duration exceeds 59 minutes. In such cases, it utilizes INT function to calculate the number of hours, followed by another IF statement to determine the correct usage of "hour" or "hours" based on the result. Subsequently, it uses MOD function to showcase the remaining minutes (after subtracting hours) as well as determine the pluralization of "minute" or "minutes". If the total duration is under an hour, the formula simply employs the MOD function for minutes count alongside the respective plurals.