Is there a way to make modifications to a nested array while simultaneously applying the changes to a specific set of cells in Google Sheets?

I have encountered an issue with my program where I am able to clear the backlog status and push changes to the segment = data [x] array, but I am unable to see those changes in the cell referenced by

var range = sheet.getRange("E2:J10");
. The problem seems to be specifically in the second if statement of the for loop.

// Description:
//The task will be available again after 14 days
//First the program will scan `Task`s to detect backlog tasks
//Then for each task, the program will calculate the difference between the current date `cDate` and the `dateOfTask` = `diff` (inDays)
//If the number of days passed is greater than 14 days, then the task will be set to an empty cell `Task.setblank` 
//Once the cell is empty, the task will be available to the algo task manager for prioritization

    function myFunction() {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getSheets()[0];
      var range = sheet.getRange("E2:J10"); //debugged // test task on line 9
    //     // Fetch values for each row in the Range.
      //const d = dRange.getValues();
      var cDate = range.getCell(1,6);
      console.log(cDate.getValue());
      var data = range.getValues();
      console.log(data);
    
        //for loop
    
    for (x=0; x<data.length; x++) {
    
    var segment = data[x];
    
    if (segment[1] == "Backlog"){
    
      var now = new Date();
      var dateOfTask = new Date(segment[5]);
      var diff = now - dateOfTask;
      var timeValue = Math.floor(diff / 1000 / 60 / 60 / 24);
      //console.log("Difference in milliseconds: ", diff); // 11140829739   
      console.log("Difference in days: ", timeValue)
    
    //var timeValue = DAYS(cDate, segment[5]);
    
      if(timeValue > 14){
      var refreashBacklog = segment.splice(1,1,"clear contents");
      range.setValue(refreashBacklog.segment);
      Logger.log(segment);
      //ask for help on stackOverflow 
      }
      else{
      continue
      }
    }
    else{
      continue // remember to set a stop at a certain row so it doesn't go to 999
    }
    }
    }

Answer №1

Here is a function that might align with your desired outcome:

function myFunction() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheetByName('Sheet1');
  var range = sheet.getRange("A1:F10");
  var values = range.getValues();

  values.forEach((row, index) =>{
    if (row[0] == "Category") {
      var currentDate = new Date().valueOf();
      var taskDate = new Date(row[5]).valueOf();
      var difference = currentDate - taskDate;
      var daysDifference = Math.floor(difference / 86400000);
      
      if (daysDifference > 30) {
        sheet.getRange(index + 1, 6).setValue("Overdue");
      }
    }
  });
}

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

Obtain the value of a two-handle slider using jQuery

Here is the HTML and JS setup I have for implementing a jQuery two-handle range slider: .html <p> <input class="amount" readonly style="border:0; color:black; background: transparent; text-align: center;" type="text"> </p> <div cla ...

The Clash of Form Action and JavaScript

Can someone help me with this issue? I have a form and a script to trigger an alert message. The code I'm using is working well: <input id="autocomplete" class="input_message" type="text" name="message" autocomplete="off" placeholder="...typ ...

Passing an array of classes in Java into another array

As a student seeking assistance with an assignment, I am tasked with creating a CollegeCourse class. This class should have fields for the course ID (e.g., “CIS 210”), credit hours (e.g., 3), and a letter grade (e.g., ‘A’). The assignment also inv ...

Is there a way to control the playback of a video, such as

Currently, I am involved in a project related to IPTV. One of my objectives is to be able to capture the moment at which a video is paused so that when clicking on another button, a small iframe opens with the same video continuing from where it was origin ...

Is there a button for invoking a PHP function?

I am fresh to the javascript realm. I've created a function in PHP. How can I trigger it by clicking a button or image in HTML? ...

Transforming astropy table columns into a numpy array

I wish to create a plot with points: points = np.random.multivariate_normal(mean=(0,0), cov=[[0.4,9],[9,10]],size=int(1e4)) print(points) [[-2.50584156 2.77190372] [ 2.68192136 -3.83203819] ..., [-1.10738221 -1.72058301] [ 3.75168017 5.6 ...

Using Nuxtjs/Toast with personalized image emblems

Would it be possible to include an icon in a toast error message, or is there a need to install another module for this functionality? I am currently using vue and attempting to integrate a component as an icon, but so far without success. this.$toast.er ...

Issues with the node.js and discord.js API due to superagent integration

Hey there, I've been working with an API that provides information based on ID inputs. Everything was running smoothly until I encountered an issue with invalid IDs. Instead of displaying a message like Invalid ID, my bot crashes when a wrong ID is en ...

Struggling to retrieve the session value using JavaScript in a C# application

Currently, I am attempting to retrieve four values from the session. However, I am only able to fetch two of them, while the other two seem to be missing. As a beginner, I apologize if my question comes across as too simplistic. Within a tree view, I have ...

Display a checkbox and automatically mark it as checked if a value from one dataset is found in another dataset

I am trying to check whether a value exists from one dataset to another dataset. Specifically, I want to utilize the id property for this purpose. I have been experimenting with handlebars.js, but the code below is not functioning properly. Here is the s ...

What is the most efficient way to organize these arrays?

I've been racking my brain trying to figure out a sorting logic for some arrays, but I'm stumped. Maybe you have an idea? Imagine we have an array of objects structured like this: let obj = {day:'2', month:'6', year:'19 ...

Generate PDF Files Using Ajax

Currently, I am utilizing FPDF to generate my report. $pdf = new Report('P','mm','A4', $_POST); $pdf->AddPage(); $pdf->Output('file.pdf','I'); Furthermore, I am employing ajax to send a request to t ...

What is the maximum file size for an AJAX POST request?

Many queries have been raised regarding the process of uploading large strings of data via AJAX to PHP. However, most inquiries are related to uploading strings of approximately 3MB. I am looking to upload a significantly larger string. In my scenario, I ...

Calculating the number of days between two given dates, including both the start and end dates

I need to calculate the number of days between two dates, including both of the dates. My current method for this task is as follows: numDaysBetweenDates(startDate, endDate) { let millisecondsPerDay = 24 * 60 * 60 * 1000; return (endDate - startDate) ...

Combine identical arrays of object keys into one unified array

https://i.sstatic.net/A2r5c.png I am striving for this particular output [ productId:106290, productserialno:[{ "12121", "212121" }] ] ...

Gradually conceal the final column of an HTML table with the combination of CSS and JavaScript

My challenge involves modifying a table on Sharepoint with responsive design in mind. The goal is to hide the last visible column in the table based on the screen's width. For instance, if a user creates a 10-column table and the screen size is 1200p ...

Embed the Three.js CSS3DRenderer scene within a designated div element

I am interested in using the Three.js CSS3DRenderer to create a three-dimensional composition. Here is the code I have: "use strict"; var OrbitControls = THREE.OrbitControls, CSS3DRenderer = THREE.CSS3DRenderer, CSS3DObject = THREE.CSS3DObject, S ...

Guide to swapping out the variables "labels" in JavaScript

Here is the object structure: { 'File_12345.ZLM': { MeterID_12345: { BASIC_INFO: [Object] } } } { 'File_678910.ZLM': { MeterID_678910: { BASIC_INFO: [Object], } } } ======================== ...

PHP and JS with Jquery often face challenges when trying to work together due to their conflicting array structures

This is a perplexing issue that has me stumped. I retrieved an array of workers from a MySQL database using json_encode and then copied it to two other arrays for future operations. var workers = <?php echo json_encode($tablica_pracownikow); ?>; va ...

Submit JSON data through an HTML form

Currently, I am working with React on the front-end and expressJs for the server. I have a JavaScript Object containing data that needs to be sent to the server. In order to achieve this, I use JSON.stringify to convert the data and then store it within a ...