我如何通过检查单元格值是否存在来对 Sheet A 执行操作,并将其用作键以在下一次执行中跳过,因为它已被处理?

How can I perform actions on Sheet A by checking cell value if exists, and use it as a key to skip in the next execution as it was already processed?

请原谅这个基本问题,但在尝试了 15 次不同的变体之后,我带着这个来到这里。下面是完整代码,但下面的语句

    if (data[i][11] <> "YES") 

似乎在我尝试过的各种方法中都没有正确执行,我确信我在这个脚本的其他地方做错了什么,但我一生都看不到它。希望新的眼睛能帮到你..

我正在尝试在 Sheet A 上收集数据,对其进行处理并将其放置在 Sheet B 上,并更新 Sheet A 中的一个密钥。如果脚本是 运行,它不应该拾取 Sheet A 已经处理过的项目(通过键 - 当前在第 12 列并指示为“是”)。在每个实例中,脚本都会继续处理所有行,无论它是否存在 - 让我认为这实际上不是我提供的条件..

希望这是清楚的。感谢任何朝着正确方向的推动。

另一个尝试:

var jiraupdated = data[i][11]; 
if (jiraupdated !== UPDATED)
//and various similar replacing with different types, methods, etc.

完整脚本:

var UPDATED = "YES";

function formatJIRASheet() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var lastRow = sheet.getLastRow();
  var startRow = 2; // First row of data to process
  var numRows = lastRow-1; // Number of rows to process
  // Fetch the range of cells
  var dataRange = sheet.getRange(startRow, 1, numRows, lastRow); //rowCount for data
  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  var ss=SpreadsheetApp.getActive();
  
  var sh1=ss.getSheetByName('JIRA Sheet');

  for (var i = 0; i < data.length; ++i) {
    // Fetch values on initial data
    var row = data[i];
    var date = row[1]; // 2nd col
    var customername = row[2]; //3rd col
    var test = row[3]; 
    var testt = row[4];
    var summary = row[5];
    var actualoutcome = row[6];
    var exptoutcome = row[7];
    var customeremail = row[8];    
    // Form new description (merge of other fields) 
    var description = (date + " " + dftdescription + " " + test + " " + testt + " " + actualoutcome + " " + exptoutcome); // target col 2
                        
    
    // This is the failing check, continuing to write records to next sheet even though they've already been covered in previous runs.  I've tried maybe 15 different methods to fix this and have came up short.  
    if (data[i][11] <> "YES") { 
      sh1.appendRow([null, "Bug", null, summary, description, customeremail, customername, null, null, null, null, null, "Low", "Low", null, null, null, null, null]); 
      sheet.activate();
      sheet.getRange(startRow + i, 12).setValue(UPDATED);
      // Make sure the cell is updated right away in case the script is interrupted
      SpreadsheetApp.flush();
    }

试试这个:

function formatJIRASheet() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('Sheet1');
  const sr=2;
  const rg=sh.getRange(sr,1,sh.getLastRow()-sr+1,sh.getLastColumn());
  const v=rg.getValues();
  const sh1=ss.getSheetByName('Sheet2');
  v.forEach(function(row,i){
    var date=row[1];
    var customername=row[2];
    var test=row[3]; 
    var testt=row[4];
    var summary=row[5];
    var actualoutcome=row[6];
    var exptoutcome=row[7];
    var customeremail=row[8];    
    var description=(date + " " + "undefined" + " " + test + " " + testt + " " + actualoutcome + " " + exptoutcome);
    if(row[11]!="YES") { 
      sh1.appendRow(['',"Bug",'',summary,description,customeremail,customername,'','','','','',"Low","Low",'','','','','']); 
      sh.getRange(sr + i, 12).setValue("YES");
    }
  });
  SpreadsheetApp.flush();
}