Creating a ChangeLog in Sheets with Additional Information

163 views
Skip to first unread message

Jordon Walker

unread,
Jul 27, 2023, 5:36:48 PM7/27/23
to Google Apps Script Community
I have code that will run every time an edit is made in a Google Sheet and print it on a separate sheet with basic information.  I need it to pass the info in the changed cell as well as another cell in the same row. However, whenever I add a line to add info from column4, nothing prints on the logchange sheet.  Below is the code with the problematic line highlighted in red.  Would someone have insight into why this is happening?

function onEdit(e) {

  const log = e.source.getSheetByName("log")
  var cellname = SpreadsheetApp.getActiveRange().getA1Notation()
  var sheetname = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getSheetName()
  var cellvalue = SpreadsheetApp.getActiveRange().getValue()

  var column4Value = SpreadsheetApp.getActiveRange().getRow().getCell(4).getValue()

 

  log.appendRow([cellname, cellvalue, sheetname, new Date(), column4Value])
}
Message has been deleted

Freelancer Techworld

unread,
Jul 28, 2023, 7:45:13 AM7/28/23
to Google Apps Script Community
Hi,

The red-highlighted line: var column4Value = SpreadsheetApp.getActiveRange().getRow().getCell(4).getValue()

This line does not work because Google Apps Script expects nothing after getRow(). In other words, getRow() function gives you an integer value (a number), so getCell(4).getValue() does not work when you put it after getRow().

Also, the getCell(4) is not correct. The correct syntax is getCell(row, column) to returns a given cell with a range.

I hope this helps!

volu...@bethleheminn.org

unread,
Jul 28, 2023, 7:58:04 AM7/28/23
to google-apps-sc...@googlegroups.com
Hi, Thank you for contacting me.

My normal office hours are 8am-4pm Monday through Friday.

If you are a volunteer with a last minute cancellation,
please reach out to one of the following phone numbers:

Redmond-(541.699.1272x13)
Bend- (541.322.8768x13)
Bend Kitchen (541.322.8768x25).

If you are a staff with an emergency, please reach out to my cell number.

Jordon Walker

unread,
Jul 28, 2023, 1:44:17 PM7/28/23
to google-apps-sc...@googlegroups.com
Thank you, that makes much more sense.  Appreciate the help

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/iPIRqxqlQhg/unsubscribe.
To unsubscribe from this group and all its topics, 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/e5735648-8aa7-4768-abde-ae5cf758957en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages