[英]Run an apps script code containing an If Statement (How To Trigger Automatically ?) - Google Apps Script / Google Sheets
I have the code below which runs as intented - if you manually run the script.我有下面的代码,它按意图运行 - 如果您手动运行脚本。
Data appears in this sheet("TOP UP NEEDED") via MoveRow Script (No Human Editing)数据通过 MoveRow 脚本(无需人工编辑)显示在此工作表中(“TOP UP NEEDED”)
function IfStatement() {
var app = SpreadsheetApp;
var activeSheet = app.getActive().getActiveSheet();
var workingCell = activeSheet.getRange(2, 1).getValue();
if (workingCell === "") return; // Modified
var sheet = SpreadsheetApp.getActive();
sheet.setActiveSheet(sheet.getSheetByName('TOP UP NEEDED'), true);
sheet.getRange('D2').activate();
sheet.getCurrentCell().setFormula('=QUERY({\'SKU & Qty\'!$A$3:$C},"SELECT * WHERE Col1 MATCHES \'" &
JOIN("|",FILTER(A:A, NOT(ISBLANK(A:A)))) & "\' ")');
addCheckboxToI2();
MoveDataToFORKLIFT();
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('TOP UP NEEDED'), true);
spreadsheet.getRange('A2:G30').activate();
spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
spreadsheet.getRange('A2').activate();
DELETESHEETS();
addCheckboxToG2FORKLIFT();
}
Currently when the data arrives in "TOP UP NEEDED" - script does not run.当前,当数据到达“需要充值”时 - 脚本不会运行。
Expected Result = When A2:A has data it should run the script.预期结果 = 当 A2:A 有数据时,它应该运行脚本。 When A2:A "" - nothing should happen.
当 A2:A "" - 什么都不应该发生。
Thank you in Advance先感谢您
From the documentation :从文档:
Script executions and API requests do not cause triggers to run.
脚本执行和 API 请求不会导致触发器运行。 For example, calling Range.setValue() to edit a cell does not cause the spreadsheet's onEdit trigger to run.
例如,调用 Range.setValue() 来编辑单元格不会导致电子表格的 onEdit 触发器运行。
If your function IfStatement()
already works, simply call it at the end of your MoveRow script.如果您的函数
IfStatement()
已经工作,只需在 MoveRow 脚本的末尾调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.