2017-08-28 141 views
0

我有這個腳本,它完美的作品 - 如果「Y」是寫在B94作爲片1谷歌腳本 - 一個運行上編輯腳本多張

function runOnEdit(e){ 
var sheets = ["Sheet 1", "Sheet 2"]; // change sheet names to suit. 
var ind = sheets.indexOf(e.source.getActiveSheet().getName()); 
if(ind == -1 || e.range.getA1Notation() !== "B94" && e.range.getA1Notation() !== "B54" || e.value.toLowerCase() !== "y") return; 
ind == 0 ? Script1() : Script2(); 
} 

,它觸發腳本1.如果它是寫在表2 B54,它觸發腳本2.

我想更多的牀單和多個腳本把它添加。

function runOnEdit(e){ 
var sheets = ["HAR 2 Yelo", "HAR 2 Bambello", "HAR 2 KM5512"]; // change sheet names to suit. 
var ind = sheets.indexOf(e.source.getActiveSheet().getName()); 
if(ind == -1 || e.range.getA1Notation() !== "B94" && e.range.getA1Notation() !== "B54"&& e.range.getA1Notation() !== "B54" || e.value.toLowerCase() !== "y") return; 
ind == 0 ? CopyYeloPlants() : CopyBambelloPlants() : CopyKM5512Plants() ; 
} 

這是行不通的。我錯過了什麼?

回答

1

你的第二個腳本不再是繼三元或有條件的運營商,這是

變量==條件的正確語法?值1:VALUE2

爲了測試幾個條件的語法將是例如:

可變==條件1? value1:variable == condition2? value2:變量== condition3? value3:value4;

或者在你的榜樣:

變量==條件1? doThis():variable == condition2? doThat():variable == condition3? doSomehingElse():return;

來吧,試試這個工作的例子。爲了可讀性,我現在開始爲每一條新線提供條件。

function answerTheQuestion() { 
//Hint: Correct answer is "A" 
var yourAnswer = "A"; //Fill in your answer here and run the script; 
yourAnswer == "C" ? Logger.log("Wrong answer!") : 
yourAnswer == "B" ? Logger.log("Try again") : 
yourAnswer == "A" ? Logger.log("That's right!") : 
Logger.log("3 strikes and your out") 
}