Why is it that when a boolean value is logged as a checkbox, it shows up as undefined?

In my code, I'm attempting to log the value of a variable named check, which corresponds to column 11 in a spreadsheet. This variable is meant to represent the state of a checkbox (true or false) based on whether it's been ticked or not. However, when I try to log this value, I keep getting an 'undefined' error message and I'm unsure why.

If anyone could provide some insight into this issue, I would greatly appreciate it. I've included a comment for your reference within the code snippet below.

function sendEmail() {

 // Function setup
 var ActiveSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
 var StartRow = 2;
 var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
 var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,11);
 var AllValues = WholeRange.getValues();

 var message = "";
 for (i in AllValues) {

 var CurrentRow = AllValues[i];

 var EmailSent = CurrentRow[13];


// Issue arises here
   var check = CurrentRow[11];
   Logger.log(check)




 if (EmailSent == "sent") 
     continue;

 // HTML template for email content
  message +=
      "<p><b>Timestamp by: </b>" + CurrentRow[1] + "</p>" +
      "<p><b>Requester Email: </b>" + CurrentRow[2] + "</p>" +
      "<p><b>Star Rating: </b>" + CurrentRow[3] + "</p>" +
      "<p><b>Request Category: </b>" + CurrentRow[4] + "</p>" +
      "<p><b>Description: </b>" + CurrentRow[5] + "</p>" +
      "<p><b>Label: </b>" + CurrentRow[6] + "</p>" +
      "<p><b>Ticket ID: </b>" + CurrentRow[7] + "</p>" +
      "<p><b>Comment: </b>" + CurrentRow[8] + "</p>" +
      "<p><b>Status: </b>" + CurrentRow[9] + "</p><br><br>";

  var setRow = parseInt(i) + StartRow;

  ActiveSheet.getRange(setRow, 13).setValue("sent");
}

 var SendTo = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32575f535b5e72575f535b5e1c5d40551c5347">[email protected]</a>" + "," + "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="85e0e8e4ece9c5e0e8e4ece9abeaf7e2abe4f0">[email protected]</a>";

 var Subject = "CT IT feedback";


  MailApp.sendEmail({
      to: SendTo,
      cc: "",
      subject: Subject,
      htmlBody: message,
});
}

Answer №1

When extracting values from a sheet, nested for loops are essential to consider. Although unfamiliar with the functions utilized in your code snippet, an example of navigating through a sheet is provided below for educational purposes.

Check out the illustration below.

var sheet = [
    [1,2,3,4],
    [5,6,7,8],
    [9,10,11,12]
];

// Visualize the array above as a representation of your sheet.
// Moving across 1, 2, 3, 4 and then down to the next row
// 5, 6, 7, 8 and so forth.

var rows = sheet.length;
var rowCount;

for(var i = 0; i < rows; i++) {
    rowCount = 0;
    for(var j = 0; j < sheet[i].length; j++) {
        rowCount += sheet[i][j];
    }
    // Completed calculation for the row.
    console.log(rowCount);
}

Answer №2

Initially, the for...in statement is designed for iterating through an object's properties, not arrays. It would be more appropriate to utilize the forEach method instead. Consider replacing your current code with the following:

 AllValues.forEach(function(CurrentRow) {

    // Code within loop

})

In addition, the variable CurrentRow is limited to index 10, making it unable to access values at CurrentRow[11] and CurrentRow[13]. To address this issue when defining WholeRange, ensure that you allocate space for at least 14 columns:

var WholeRange = ActiveSheet.getRange(StartRow, 1, RowRange, 14);

I trust that this information proves beneficial!

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

Why does the Formik form only validate after the second button click in this React Hooks, TypeScript, Formik, NextJS setup?

Looking for fresh perspectives on my code. The issue lies in the fact that it takes two submission attempts to validate the data inputted into a form successfully. It appears that the post request to Airtable happens before the validation schema, resulting ...

Encountering an issue with the history module when utilizing the webpack dev server

I am encountering an issue while trying to run webpack dev server. The history functionality was working fine until I started using the webpack module. A warning message appeared in my console: WARNING in ./src/history.js 2:15-35 export 'createBrows ...

Enhancing Chat: Updating Chat Messages in Real-Time with Ember.js and Firebase

I recently started working with ember.js and firebase. Right now, I have successfully implemented a feature to post messages and view them in a list format as shown below: //templates/show-messages.hbs {{page-title "ShowMessages"}} <div clas ...

Module child-process not found

Why is it that when I try to run "require('child-process')" in the node shell, I receive an error saying "Cannot find module 'child-process'"? It seems like "child-process" should be a default library in Node. Any insights on what could ...

Troubleshooting Angular 5: Interceptor Fails to Intercept Requests

I have a valid JWT token stored in local storage and an interceptor that I borrowed from a tutorial. However, the interceptor is not intercepting requests and adding headers as expected. Here's where I am making a request: https://github.com/Marred/ ...

Steps for exporting various elements from a .vue file

In my Vue project, I am incorporating TypeScript along with Vue. There is a specific scenario where I need to export multiple items from my .vue file. Here's an example of what I want to achieve: // FooBar.vue <template> ... </template& ...

The onClick event function is activated when the component is first rendered on the screen

Below is the function in my component: myFunc = () => {...} This is how I implemented it: <MyComponent onClick={this.myFunc()}/> The onClick function will trigger when the component mounts. However, if I use either of these alternatives: < ...

Is it possible to preserve the query parameters from the previous page using Vue Router's Navigation guard feature?

Hey there! So, I'm looking to pass a query from the current page to the next one without manually coding it into all of my push functions. I was wondering if there's a way to do this through Navigation guard or some hooks? I did some research an ...

Develop a JavaScript function to declare variables

I am currently attempting to develop a small memory game where the time is multiplied by the number of moves made by the player. Upon completion of all pairs, a JavaScript function is executed: function finish() { stopCount(); var cnt1 = $("#cou ...

How come the values keep appearing without any loops or subsequent calls being made to the PHP file?

Here is a demo example showcasing 'Server Sent Events(SSE)': Embed HTML code(index.html) : <!DOCTYPE html> <html> <body> <h1>Receiving server updates</h1> <div id="result"></div> <script> if(type ...

Steps for ordering by a JSON attribute:

Within my JSON file, I have the following simple structure: {"Item1": {"p1": {"p1sub1": 8, "p1sub2": 7}, "p2": {"p2sub1": 6, "p2sub2": 5} }, "Item2": {"p1": {"p1sub1": 4, "p1sub2": 3}, "p2": {"p2sub1": 2, "p2sub2": 1} } } To retrieve this data, I use th ...

Employing promises for fetching data via XHR results in a promise that is still pending

Currently, I am experimenting with promises to handle asynchronous requests using XHR. Interestingly, I noticed that when I try to log the result within the .then function, it works perfectly fine. However, if I attempt to log it outside of this scope, it ...

Checkbox value not being accurately retrieved by Struts2 page

I have a form that captures phone information for two different phones, with each phone having its own set of details. If the user enters the same phone number for both phones, the second checkbox is automatically checked using the JavaScript code below: ...

Retrieve the values of a particular key from your Django queryset JSON data and then seamlessly send them over to VueJS

I recently developed a web app using Django2 with Vue for the frontend. I encountered an issue in passing all values of a specific key from JSON data to a JavaScript dictionary value on the frontend. Despite trying to use the += operator to add the data, I ...

Discovering the correct element and typing for an HTML attribute through JavaScript

We are currently working on test automation and I am looking for a way to identify the Element and Type associated with it within an html (Data-qa) attribute. For example, when looping through, the Element is identified as input and the type is radio. < ...

Concealing a Div element without the use of Jquery or JavaScript

I have an Upper and Lower div in my HTML code. I am trying to display the Lower div only if the Upper div is present, otherwise hide it. Is there a way to achieve this using CSS without using Jquery or Javascript? Note: No modifications should be made t ...

Accessing the page directly in a Nuxt SPA is not permitted

I'm currently working with Nuxt version 2.3.4. In my project, I am utilizing vue-apollo to fetch data for a file named pages/_.vue, which dynamically manages content. As indicated on this documentation page, this is the recommended approach for handli ...

Error: Unable to locate sportsRecord due to missing function

updated answer1: Greetings, I have updated the question with some detailed records and console logs for better understanding. sportsRecord = { playerTigers:[ {TigerNo: 237, TigerName: "Bird Bay Area", TigerkGroupNo: 1, isDefault: true ...

Is it possible to save the video title as a variable using YTDL-core?

Is there a way to store the video title as a global variable in JavaScript? ytdl.getBasicInfo(videoURL, function(err, info) { console.log(info.title) }); I have been trying various methods but I am unable to successfully define a variable to hold the v ...

A mistake occured: Unable to modify the stack property of [object Object], as it only has a getter method

Encountering an error when attempting to use a service in my component and declaring it in the constructor - TypeError: Cannot set property stack of [object Object] which has only a getter This is the code snippet: import { Component } from '@angula ...