2

I have a spreadsheet, as well as a master copy of the spreadsheet. Every time user enters data into a cell, it takes the new data and throw into the master copy.

Recently however, I noticed a user creating a new column, which was not captured by OnEdit().

Hence I looked it up and saw OnChange(), which was implemented last year.

However, I do not know how to use that trigger.

How do I retrieve the new column or row, or the merged cells that the user changed, and duplicate it into my master copy? I can't find documentation on this.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
chopz
  • 381
  • 1
  • 5
  • 21

1 Answers1

15

To get all the methods in an object you can use the following:

function onChange(e){
  for( i in e )
    Logger.log( i );
}

In this logging you can spot the useful source property, which has the following properties/methods (found using for( i in e.source)):

getOwner
getKey
removeNamedRange
revealColumn
getSheetPermissions
deleteSheet
getViewers
unhideRow
addEditors
getSpreadsheetTimeZone
insertRowBefore
getSheetId
setFrozenRows
setSpreadsheetLocale
getSpreadsheetLocale
getId
copy
hideColumn
getActiveRange
addMenu
toast
setColumnWidth
getLastColumn
getAs
insertColumnsAfter
setSheetPermissions
setActiveSheet
getBlob
removeMenu
sort
getRange
getRangeByName
getColumnWidth
hideRow
inputBox
removeViewer
findSheetByName
insertImage
autoResizeColumn
setNamedRange
getSheetByName
setActiveCell
insertSheet
isWritable
setSpreadsheetTimeZone
getNumSheets
setFrozenColumns
getSheetProtection
duplicateActiveSheet
deleteRow
isAnonymousWrite
isAnonymousView
findSheet
insertRowAfter
addEditor
getName
unhideColumn
setRowHeight
addViewers
rename
show
setActiveRange
getFrozenRows
setAnonymousAccess
addCollaborator
setActiveSelection
getSheetValues
deleteActiveSheet
removeCollaborator
getDataRange
addCollaborators
deleteRows
deleteColumn
toString
isReadable
removeEditor
setName
insertColumnsBefore
moveActiveSheet
getSheets
getChanges
appendRow
getSheetName
getActiveSelection
insertRowsBefore
insertColumnAfter
getActiveCell
getActiveSheet
getEditors
find
getRowHeight
getFormUrl
getFrozenColumns
updateMenu
msgBox
insertColumnBefore
getUrl
getLastRow
insertRowsAfter
renameActiveSheet
setSheetProtection
deleteColumns
addViewer
getCollaborators
revealRow
Kriggs
  • 3,731
  • 1
  • 15
  • 23
  • the source is just A Spreadsheet object, representing the Google Sheets file to which the script is bound. – vstepaniuk Aug 15 '23 at 16:03
  • why this is an accepted answer I dont undestand – vstepaniuk Aug 15 '23 at 16:04
  • @vstepaniuk this is an 8 year old answer, at the time GAS was at it's infancy and documentation was scarce, onChange for example had only a stub with the title and no methods at the time of writing this answer, so this was the best we got to get around on how to use it at that time. Luckily this answer is probably depracated, feel free to post a better one and help anyone that lands here. – Kriggs Aug 17 '23 at 12:08