Timestamp based on keyword within an array

41 views Asked by At

I would like to make a function that will create a timestamp whenever a particular keyword is mentioned in a specified array. For example, if the array included the word "Item 1" in a cell, create a timestamp when it was populated in the sheet. Then if the next last line contains the word "Item 2" in a cell, create a timestamp when is was populated in the sheet. I assume I will need an if statement or for loop to perform the function. A portion of my script is below as reference:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName('Form Response Data');
var sheet4 = ss.getSheetByName('Dewar ID');
var last_dewar = sheet4.getRange('A3:A50').getValues();
var last_entry = sheet1.getRange(sheet1.getLastRow(),1,1,sheet1.getLastColumn()).getValues();
1

There are 1 answers

5
Cooper On

Is keyword in array?

function isKeywordInArray(keyword) {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  const array = sh.getDataRange().getValues().flat();
  if(~array.indexOf(keyword) {
    sh.getRange("A1").setValue(new Date());//you pick the range
  }
}