I have a apps script which had three OnEdit()
triggers, as below
function onEdit(e) {
onEdit1(e); // The function for hide/unhide sheets/tabs
onEdit2(e); // The function for hide/unhide row in ESS sheet
onEdit3(e); // The function for hide/unhide rows in a
}
function onEdit1(e) {
var cp = SpreadsheetApp.getActiveSpreadsheet();
var a = cp.getSheetByName("A");
var b = cp.getSheetByName("B");
var check_value = cp.getSheetByName("check sheet");
var cella = check_value.getRange('C6');
if (cella.getValue() == 'Yes') {
a.showSheet();
}
else {
a.hideSheet();
}
var ç = check_value.getRange('C7');
if (cellb.getValue() == 'Yes') {
b.showSheet();
}
else {
b.hideSheet();
}
}
function onEdit2(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ESS = ss.getSheetByName("BBB");
var cellx = ESS.getRange("D13");
if ((cellx.getValue() == "Accept") || ((cellx.getValue() == ""))){
ESS.hideRows(15);
}
else {
ESS.showRows(15);
}
}
function onEdit3(e) {
var sd = SpreadsheetApp.getActiveSpreadsheet();
var info = sd.getSheetByName("Z");
var a = sd.getSheetByName("A");
var check = info.getRange("J9");
if (check.getValues()== "Direct"){
a.hideRows(37,8);
}
else{
if((check.getValues()== "Indirect") || (check.getValues()== "")){
a.showRows(37,8);
}
There are no errors and the execution completes without any errors but upon changing/editing the values the hiding/unhiding for the sheet and rows does not happen.
I did try to look at other posts on the timing out of onEdit() function, but am unable to understand what changes to make in my code.
Also when I look at the Executions
I get Function- onEdit(), Type- Simple Trigger, Status- Timed Out
Please help me with this
CodePudding user response:
Try this:
function onEdit(e) {
var a = e.source.getSheetByName("A");
var b = e.source.getSheetByName("B");
var csh = e.source.getSheetByName("check sheet");
var [cella, cellb] = csh.getRange("C6:C7").getValues().flat();
if (cella == 'Yes') { a.showSheet(); } else { a.hideSheet(); }
if (cellb == 'Yes') { b.showSheet(); } else { b.hideSheet(); }
var esh = e.source.getSheetByName("BBB");
var cellx = esh.getRange("D13").getValue();
if ((cellx == "Accept") || ((cellx == ""))) { esh.hideRows(15); } else { esh.showRows(15); }
var shz = e.source.getSheetByName("Z");
var sha = e.source.getSheetByName("A");
var check = shz.getRange("J9").getValue();
if (check == "Direct") { sha.hideRows(37, 8); } else {
if ((check == "Indirect") || (check == "")) {
sha.showRows(37, 8);
}
}
}
CodePudding user response:
You should check your code for typos.
cellb is not defined
if (cellb.getValue() == 'Yes') {
Change getValues() to getValue(). getValues() returns an array not a value.
if (check.getValues()== "Direct"){
if((check.getValues()== "Indirect") || (check.getValues()== "")){
To:
if (check.getValue()== "Direct"){
if((check.getValue()== "Indirect") || (check.getValue()== "")){