Receive the values starting from the second one, onwards

Looking for help with a problem that I posted on Stack Overflow

Although the issue has been resolved, I am now wondering how to extract the second or third value from it. With multiple tables in the sheet, I will eventually need totals for each of them. Additionally, is there a way to automatically identify the array number containing date rows for each table without manually defining it? I hope this explanation is clear.

Thank you!

Best regards,

L.E. Access test file here

Answer №1

If I understood your query correctly, instead of stopping the loop when a match to "Total" is found, perform necessary actions within the loop as shown below:

var today = toDateFormat(new Date());
var todaysColumn = 
    values[5].map(toDateFormat).map(Number).indexOf(+today);
var emailDate = Utilities.formatDate(new Date(today),"GMT+1", 
                                     "dd/MM/yyyy");
for (var i=0; i<values.length; i++){
  if (values[i][0]=='Total'){
    nr = i;
    Logger.log(nr); 

    var output = values[nr][todaysColumn];
    //     Deal with the output here - assuming it will be emailed

  }
}

The loop will continue and find every instance of "Total" to execute the same action. This approach assumes that the "Totals" are in the same column. You can customize this further if you only want specific tables to trigger an action, but this should give you a starting point.

I may have not fully grasped the second part of your question...

"Also, is there any solution to automatically find the array number which contains the date row for each table (instead of defining this manually)? Hope this explanation makes sense."

I presume you wish to identify all rows containing "Total" in a particular column. You could initialize a variable as an empty array like so, var totals = [];. Then, rather than executing the action in the initial loop, push the row values to the array using

totals.push(nr+1) . //adding 1 gives you the actual row number (rows count from 1 but arrays count from 0)
. Subsequently looping through the totals array would enable you to perform desired actions. Alternatively, you could create an array of all the values instead of row numbers like
totals.push(values[nr][todaysColumn])
and iterate over that array. There are numerous methods to tackle this issue!


Based on our previous discussion, I have made adjustments to the "test" sheet and updated the code. Below are my revisions

All modifications have been applied in your test sheet and confirmed functional in Logger. Feel free to reach out if you have any queries.

Spreadsheet:

  1. Added "Validation" Tab
  2. Adjusted "Table" tab so that the row with "Email Address" in Column A aligns with the desired lookup values (dates or categories)...this was specifically done for the first two tables as others already met this criteria.

Code: Create table/category selector...

  1. In the editor navigate to File >> New >> HTMLfile
  2. Name the file "inputHTML"
  3. Paste the provided code into that file

<!DOCTYPE html> ... [Code truncated for brevity]

Edits to Code.gs file Replace existing code in Code.gs with the revised version...

//This simple trigger generates the menu item in your sheet
function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Run Scripts Manually')
  .addItem('Get Total','fncOpenMyDialog')
  .addToUi();

}
//Function to open the dialog triggered by the menu item
function fncOpenMyDialog() {
  //Launch a dialog
  var htmlDlg = HtmlService.createHtmlOutputFromFile('inputHTML')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setWidth(200)
      .setHeight(150);
  SpreadsheetApp.getUi()
      .showModalDialog(htmlDlg, 'Select table to get total for');
};


//Main function triggered by clicking "Get Total" in the dialogue...variables passed from formSubmit in inputHTML javascript
function getTotal(table,catagory) { ... [Code truncated for brevity]

/** Functions below populate selects used by the form **/
function getTables(){ ... [Code truncated for brevity]

function getCatagories(){ ... [Code truncated for brevity]

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

How to enable drag-and-drop functionality for an iframe?

I've successfully made a chat widget draggable using react-draggable. However, the chat widget is also consumed by an iframe created entirely with HTML. I need the iframe to be draggable as well, but react-draggable doesn't support this. Are ther ...

MongoError: What to do when the pipeline needs text score metadata, but no text score is provided?

When I run the following command directly in MongoDB 3.6.6 shell, I encounter an error that says "pipeline requires text score metadata, but there is no text score available." I'm not sure where to begin troubleshooting this issue. Here's how I ...

Step-by-step guide on generating a numpy array while iterating through a loop

I currently have a numpy list that contains arrays (a two-dimensional list): db = [ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8, ch9, ch10, ch11, ch12, ch13, ch14, ch15, ch16] My goal is to apply operations to these arrays as shown below: for i in db: new ...

Experiencing the issue of receiving `undefined` when trying to access res.query with a JSON query string using

Utilizing qs for constructing JSON-based query parameters for my REST API request: On the client side: import qs from "qs"; let query = { dateTime: { $gte: 1664557995000 } }; let q = qs.stringify(query); let url = "http://lo ...

Issue with recursive function not adding elements to an array

I have created a function that generates a matrix of date pairs. Basically, it takes two dates and adds 31-day ranges to an array, resulting in something like: [[date, date+31], [date, date+31], ...] The function is implemented using recursion: public fu ...

Nested Views in Angular UI Router

I have a specific structure set up like this: <div ui-view="main"> <!-- content is dynamically loaded here by AngularJS ui-router --> <aside ui-view="sidebar"> <!-- sidebar content is also populated by AngularJS ui-router --&g ...

If the option of "none" is chosen, I would like to deactivate all checkbox selections

Struggling with disabling all checkboxes in a PHP form when the NONE option is selected. <h5>HEALTH OF STUDENT</h5> <p>Any physical, emotional, or other difficulties to be aware of?</p> <table> <td>Hearing ...

Displaying the identical date on two separate Ajax Calendar Extender controls in Asp.net

I am facing an issue with some ajax calendar extenders. I have two similar calendars and two textboxes, each linked to one calendar. <asp:TextBox ID="txt1" runat="server"</asp:TextBox> <cc1:CalendarE ...

Designing webpages by superimposing text onto images with customizable positioning

My current project involves developing an HTML document with a floor plan image as the main layer. On top of this image, I need to display employee names extracted from a database and positioned on the map based on a location variable within the database ...

Restricting the rotation of a camera in Three.js

Within my Three.js project, there is a 3D scene featuring a floor and an orthographic camera. I have successfully enabled the user to navigate the scene using their mouse. However, I am facing a challenge in restricting the camera's movement within t ...

Generate an array by collecting all the DIV elements, then proceed to compare for any

I need to create a form that checks if the user has entered a specific word in a textarea. These words are stored in arrays generated from divs. I am having trouble with the verification part, and I believe my arrays may not be created correctly. Take a l ...

Achieve focus in EditorFor MVC using JavaScript

You have a button that triggers a pop-up window <a data-dialog="AddProduct" href="@Url.Action("AddProduct", "Outputs")" id="addproduct" class="pop-up-window btn btn-success">Add Product <span class="glyphicon glyphicon-plus-sign" aria-hidden= ...

Unable to eliminate user registration feature with Meteor and React

Exploring the world of Meteor and diving deep into its functionalities, I am currently focused on creating a user login and signup page with personalized control panels for each registered user. Although I have successfully implemented the signup and logi ...

How can I call a function in the parent component when clicking on the child component in Angular 1.5?

In my Angular 1.5 app, I have two components. The first one is the parent: angular. module('myApp'). component('myContainer', { bindings: { saySomething: '&' }, controller: ['$scope', functio ...

Creating synchronous automation in Selenium: A step-by-step guide

I am feeling increasingly frustrated at the moment and I am hoping to seek assistance on stackexchange. First and foremost, I must admit that I am not a seasoned Javascript developer, probably not even an experienced developer overall, but I do have some ...

Acquire the worth of the <MenuItem> element from React's mui/material library

I am attempting to retrieve the value of the selected item listed below: Here is my attempt at logging this information: console.log("Event: ", event.currentTarget); Output: <li class="MuiButtonBase-root MuiMenuItem-root MuiMenuItem-gut ...

Using Function Call to Generate Components in React

Being tired of repeatedly defining states to render Components based on conditions, I often find myself just wanting to display notifications or alerts. My current dilemma is figuring out how to render a component by invoking a function from within that co ...

Send the output of an asynchronous ajax request to the designated function within the jQuery Validation plugin

Utilizing the jQuery Validation plugin (JVP) for server-side validations via ajax has been seamless, except for one hitch: JVP struggles with performing remote validation on blank fields. While it's easy to use its default required: true rule for sim ...

Having trouble with retrieving an array from a function within a class

I've been working on a PHP class that handles 'cars'. In this class, I attempted to create a recursive function called listRedCars() that should return an array containing all the red cars from the $cars property. However, I'm encounte ...

Obtaining and Assigning Filter Values in Material Table

Is there a way to programmatically obtain and adjust filter values with material-table? I am looking to enable users to save filter settings as reports and access them whenever necessary. ...