Having trouble with a lengthy formula in your Google Sheets Apps Script function? You may encounter an error like `SyntaxError: missing ) after argument list line: 14 file: new line.gs`. Let

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.)

  1. 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.

  2. 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.

Answer №1

function addNewRow() {
  var spreadsheet = SpreadsheetApp.openById("redactedforprivacy");
  var mainSheet = spreadsheet.getSheetByName("Main");
  mainSheet.insertRowBefore(3);
  
  var currentDate = new Date();
  var monthValue = currentDate.getMonth() + 1;
  var dayValue = currentDate.getDate();
  var yearValue = currentDate.getFullYear().toString().substr(-2);
  var formattedDateValue = monthValue + "/" + dayValue + "/" + yearValue;
  
  mainSheet.getRange("A3").setValue(formattedDateValue);
  mainSheet.getRange("C3").setFormula("=ADD(C4,B3)");
  mainSheet.getRange("H3").setFormula('=IF(E3+F3>59,INT((E3+F3)/60)&IF(INT((E3+F3)/60)=1," hour"," hours")&" and "&MOD(E3+F3,60)&IF(MOD(E3+F3,60)=1," minute"," minutes"),MOD(E3+F3,60)&IF(MOD(E3+F3,60)=1," minute"," minutes"))');
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Vue: Changing the value in the select dropdown causes input fields to reset their content

After setting up a form with input values, I noticed that when using a select element with a v-model to change the dropdown value, the input fields from the previous selections are cleared. This has been a persistent issue for me and is now starting to imp ...

Place a drop-down menu inside the input box

Struggling with this issue, I've come across various messy solutions, but I'm determined to find a cleaner one. What I'm looking for is an input field that includes a dropdown selection on the left side. This is essentially what I have in m ...

cross-domain policy file

Currently, I am attempting to make a web service call from JavaScript using AJAX: $.ajax({ type: "GET", url: "http://[REMOTE-SERVER-IP]:8080/api/service", contentType: "application/jsonp", crossDomain: true, success: successFunc, ...

If the prompt displays 'Monday', then you can output the following days in the console: 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', and 'Sunday'

Could someone assist me with modifying my code so that the entered day is displayed at the end of all days in the console? Currently, it shows up at the top. Here is what I have tried: JavaScript const daysOfWeek = ["monday", "tuesday" ...

Having difficulty duplicating a button with a click event using jQuery

I have implemented a button that reveals a phone number when clicked using the code below: var shortNumber = $("#phone_ch").text().substring(0, $("#phone_ch").text().length - 12); var onClickInfo = "_gaq.push(['_trackEvent', 'EVENT-CATEGOR ...

Switch the array's value if the key is a match?

I'm currently facing an issue where my code does not push the object when the key matches. How can I update the value of the key instead when there is a match? this.state.data.concat(items).filter(function (a) { return !this[a.key] && (th ...

Error in canvas-sketch: "THREE.ParametricGeometry has been relocated to /examples/jsm/geometries/ParametricGeometry.js"

I recently started using canvas-sketch to create some exciting Three.js content. For my Three.js template, I utilized the following command: canvas-sketch --new --template=three --open The version that got installed is 1.11.14 canvas-sketch -v When atte ...

Node.js in action with XmlHttpRequest

I'm having trouble making an XMLHttpRequest call from my client-side JavaScript to my Node server. It seems like nothing is happening and I'm a bit new to this concept. Here's the JavaScript function I've written: function sendTokenToS ...

Align pictures in the middle of two divisions within a segment

This is the current code: HTML: <section class="sponsorSection"> <div class="sponsorImageRow"> <div class="sponsorImageColumn"> <img src="img/kvadrat_logo.png" class="sponsorpicture1"/> </div& ...

Tips for modifying the color or personalizing the header arrow for the expandableRow within Mui Datatable

My MUI data table has the expandable rows option, along with an ExpandAll button in the header row. The arrow displayed in the title row is confusing for users as it's similar to the arrows in all other rows. I want to change the color of the header a ...

Validating whether another element is checked when a radio button is unchecked

I'm completely stuck on this issue - I just can't figure out how to dynamically change the image when a user unchecks a radio button (i.e., checks a different radio button). Here is the code: handleCheckbox = e => { let target = e.targe ...

How to modify a variable within the "beforeSend: function()" using Ajax and jQuery

I am facing an issue with my ajax contact form. The beforeSend function is supposed to validate the inputs and pass the parameters to a PHP file for sending emails. However, I always receive false instead of true even when the inputs are valid. I suspect ...

Mistakes within the react-router-dom package

I have been trying to connect MongoDB Realm to React by following a tutorial. Unfortunately, the tutorial is outdated and I encountered errors while trying to run the code. Initially, I received a warning stating that the leaf route does not have an elemen ...

Encountering an issue when trying to run npm run dev-server on Windows 10

Having trouble running the dev-server for superset-frontend. Encountering this error message. Any assistance would be greatly valued.https://i.stack.imgur.com/zsVU4.png ...

I am having trouble with my quiz function as it only checks the answer correctly for the first question. Does anyone have suggestions on how to make it work for

Currently, I'm tackling a quiz project that was assigned to me during my bootcamp. My focus right now is on the checkAnswer function, which evaluates the answer selected by the player. const startButton = document.querySelector(".start") as ...

When working with GWT, you can easily attach an event listener to any element on the host page

I am looking to implement a MouseOver event handler for any tag, specifically targeting anchor tags in a legacy HTML page. Following a GWT guide, I successfully utilized their JSNI method to retrieve all anchor tags with some minor adjustments for errors. ...

My JavaScript code is functioning properly in jsfiddle, but when I try to run it on my own website, I encounter

Encountered an error message stating "Uncaught typeError: cannot call method 'hover' of null" following the line $('#nav li a').hover(function(){ in my JavaScript code. Check out the code on my site here: http://pastebin.com/GjZBEu3s Y ...

What are all the different methods I can use to transfer element A to element B, and what are those methods?

While experimenting with Jquery, I encountered a roadblock and now have this question in mind. I wish to enclose all the anchor elements within a newly created div element. <td class="cont-mod-none-options" valign="top" align="right"> <a hr ...

In React, the error message "Joke.map is not a function" indicates that

export default App I am encountering an error in this code which says joke.map is not a function. Can someone please assist me in finding a solution? I have verified the api endpoints and also checked the function. import { useEffect, useState } from &ap ...

Is there a way to restrict access to my website to only be opened in the Chrome browser?

Is there a way to prevent my web application from loading when the link is opened in browsers other than Chrome? Can this be achieved using Javascript or Java? I want to restrict the usage of my web application to only Chrome. Any assistance would be appre ...