0
votes

I am aware of built-in triggers in google script API like:

  1. onEdit(event)
  2. onChange(event)

I need a function that triggers when user moves a cell around and saves the originalPosition of a cell and a target position of a cell.

For example:
1. user has in A1 something like this "val"
2. he drags the cell A1 to B3. (content & formatting and everything is moved to B3, A1 clears up).

onEdit(e) fires and I need to save the position "A1" and "B3" as original / target destination.

Is something like this possible in google sheet script?

My attempts:

Logger.log('val: %s', eventFired.range.getA1Notation());

[18-06-11 16:10:54:643 CEST] val: K5

range is saving only the target cell.

  • eventFired.oldValue stores only old value in target cell
  • eventFired.value stores only new value in target cell

I cannot find information about cell position it was moved from.

1
Have you tried anything at all? You mention two triggers, but do not appear to know if they work for your purposes. Review the event objects available to you in Apps Script documentation, and then figure out where you want to save the information. Consider also when writing your functions that the user is free to select and move as many cells as they like at once.tehhowch
There is no onChange(event) reserved function name. A simple trigger for "Change" does not exist. The "change" event only exists for Sheets, and can only be used as an "installed" trigger. Event Objects You can get the range that was edited from eventObject.range You should be able to quickly write some simple code and test it to see what happens. Use Logger.log() to see what the code is actually doing. Troubleshooting Apps ScriptAlan Wells

1 Answers

0
votes

There isn't information about your enquiry on the official docs because the spreadsheet event objects doesn't support this case as you expect. Feature requests on this matter should be sent to Google through Google Apps Scripts Issue Tracker.

As a workaround you could create a script that makes the cell/range move of the selected cell/range and trigger it through a menu, image or sidebar including a prompt or dialog to ask for the destination.

References from Google Apps Script official website