Re: [Apps-Script] Google Sheet Script Issue

32 views
Skip to first unread message

Martin Molloy

unread,
Mar 9, 2022, 7:35:43 AM3/9/22
to google-apps-sc...@googlegroups.com
Hi David

Looks OK to me. This version works for me. I added a log to make sure that the onEdit script was firing and picking up teh cell

  function hideAsset() {
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sheet = ss.getActiveSheet()
  var dropDown = sheet.getRange('A13').getValue()
 
  if(dropDown == 'NO'){
  sheet.hideRows(14,33)
  }
 if(dropDown == 'YES'){
  sheet.showRows(14,33)
  }
 
}

function onEdit(e){
var cell = e.range.getA1Notation()
console.log(cell)
if (e.range.getA1Notation() == 'A13'){
hideAsset()
}
}

Martin



On Wed, 9 Mar 2022 at 11:18, David Sternberg <da...@herefordrisk.co.za> wrote:
Hi,

I'm new to scripts but have written a short script to hid and unhide rows in a Google Sheet.

The script is triggered when a specific drop down is changed from NO to YES or YES to NO.

I can see that the script executes on the trigger  but does not run. If I run the script from the script editor it works perfectly.

I can not figure out why it triggers but does not run as it should from the sheet.

Screenshot 2022-03-09 12.10.46.png
Hoping someone can assist.

Thanks,

David.
David Sternberg
Short Term Broker
Director (Information Officer)
087 135 9111
031 832 4596
083 340 5669
da...@herefordrisk.co.za
68 Old Main Road
​Kloof, KwaZulu Natal, 3610
PO Box 1476
​Kloof, 3640
herefordrisk.co.za
All Hereford Group subsidiaries that render financial services are duly authorised in terms of the FAIS Act. In formulating the information in this message, the Hereford Group has taken due care to ensure that the information contained herein is relevant and accurate. This information is intended for google-apps-sc...@googlegroups.com only and is private and protected by law and any disclosure, copying or distribution of this information is prohibited. The information is subject to change without notice. Any legal, technical or product information contained herein is not to be construed as advice by the Hereford Group, and no representation, warranty or undertaking (expressed or implied) is given and no responsibility or liability is accepted by the Hereford Group. Hereford Direct (Pty) Ltd t/a Hereford Risk Management Services is an Authorised Financial Services Provider (Licence No. 43373)

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/68d884d4-439c-402e-924b-8103df56dbc8n%40googlegroups.com.

Bruce Mcpherson

unread,
Mar 9, 2022, 8:39:02 AM3/9/22
to google-apps-sc...@googlegroups.com
This is a bit simpler and more efficient.

function onEdit(e) {
if (e) {
const a1 = e.range.getA1Notation()
const sheet = e.range.getSheet()
const sheetName = sheet.getName()
if (a1 === 'A13' && sheetName === 'Sheet1') {
const value = e.range.getValue()
if (value === 'NO') {
sheet.hideRows(14, 33)
} else {
sheet.showRows(14, 33)
}
}
}
}

Romualdo Rubens de Freitas

unread,
Mar 9, 2022, 11:22:46 AM3/9/22
to Google Apps Script Community
Hi David,

In JavaScript == is different from ===. The first one make some conversions as requeried, while the second compares without any converstion.

Maybe you can use 'toUpperCase()' or 'toLowerCase()' string functions in comparison.

Reply all
Reply to author
Forward
0 new messages