Google Scripts: onEdit of non active sheet? The Next CEO of Stack OverflowWhy don't self-closing script tags work?Where should I put <script> tags in HTML markup?Why does Google prepend while(1); to their JSON responses?Copy submitted Form Responses to a New Sheet (PROJECTS) and wanting to be able to editGoogle Scripts for Sheets - onEdit and “source”How to prevent updates in TRANSPOSE range from messing up header order on other sheet?Google Sheets execute script onEditCustom Email based on Cell values in google sheetsGoogle Sheets: How to Move Data Between Sheets based on Text and DateTrying to convert Google Sheets moveTo script to copyTo script
Why did CATV standarize in 75 ohms and everyone else in 50?
What flight has the highest ratio of time difference to flight time?
Easy to read palindrome checker
Reference request: Grassmannian and Plucker coordinates in type B, C, D
Why do airplanes bank sharply to the right after air-to-air refueling?
Powershell. How to parse gci Name?
Why is information "lost" when it got into a black hole?
How to check if all elements of 1 list are in the *same quantity* and in any order, in the list2?
Flying from Cape Town to England and return to another province
Is it okay to majorly distort historical facts while writing a fiction story?
Axiom Schema vs Axiom
What steps are necessary to read a Modern SSD in Medieval Europe?
Is it my responsibility to learn a new technology in my own time my employer wants to implement?
Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?
Solving system of ODEs with extra parameter
Why didn't Khan get resurrected in the Genesis Explosion?
Can you be charged for obstruction for refusing to answer questions?
What did we know about the Kessel run before the prequels?
WOW air has ceased operation, can I get my tickets refunded?
RigExpert AA-35 - Interpreting The Information
Which one is the true statement?
Is micro rebar a better way to reinforce concrete than rebar?
A Man With a Stainless Steel Endoskeleton (like The Terminator) Fighting Cloaked Aliens Only He Can See
Would a completely good Muggle be able to use a wand?
Google Scripts: onEdit of non active sheet?
The Next CEO of Stack OverflowWhy don't self-closing script tags work?Where should I put <script> tags in HTML markup?Why does Google prepend while(1); to their JSON responses?Copy submitted Form Responses to a New Sheet (PROJECTS) and wanting to be able to editGoogle Scripts for Sheets - onEdit and “source”How to prevent updates in TRANSPOSE range from messing up header order on other sheet?Google Sheets execute script onEditCustom Email based on Cell values in google sheetsGoogle Sheets: How to Move Data Between Sheets based on Text and DateTrying to convert Google Sheets moveTo script to copyTo script
On sheet1 there is a submit button which runs a script and moves data into sheet2.
I'm 'timestamping' the move (under certain conditions to prevent overwriting, and pointless timestamps), however with the current script—
Issue (1): onEdit only takes place if I manually make an edit on sheet2 (=sheet2 is active).
RESOLVED! (See comments) Issue (2): onEdit won't restrict to sheet2, and will happen as well on sheet1.
function onEdit()
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
if( sheet.getName() == "sheet2" )
var activecell = sheet.getActiveCell();
if( activecell.getColumn() == 2 )
var pastecell = activecell.offset(0, -1);
if( pastecell.getValue() === '' & activecell.getValue() != '' )
pastecell.setValue(new Date()).setNumberFormat('YY-MM-DD HH:mm:ss');
Anyone know how two fix this?
Your help and insight is much appreciated!
javascript google-apps-script google-sheets
add a comment |
On sheet1 there is a submit button which runs a script and moves data into sheet2.
I'm 'timestamping' the move (under certain conditions to prevent overwriting, and pointless timestamps), however with the current script—
Issue (1): onEdit only takes place if I manually make an edit on sheet2 (=sheet2 is active).
RESOLVED! (See comments) Issue (2): onEdit won't restrict to sheet2, and will happen as well on sheet1.
function onEdit()
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
if( sheet.getName() == "sheet2" )
var activecell = sheet.getActiveCell();
if( activecell.getColumn() == 2 )
var pastecell = activecell.offset(0, -1);
if( pastecell.getValue() === '' & activecell.getValue() != '' )
pastecell.setValue(new Date()).setNumberFormat('YY-MM-DD HH:mm:ss');
Anyone know how two fix this?
Your help and insight is much appreciated!
javascript google-apps-script google-sheets
ISSUE (2) RESOLVED! By simply changing—var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
to:var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet
– saadya
Mar 21 at 18:45
It is absolutely intentional that edit triggers do not activate for programmatic edits. If you're editing programmatically, you can just call the desired function from your program already.
– tehhowch
Mar 21 at 18:50
@tehhowch Yup! Just realized that🤦♀️ Going to timestamp straight in the move function. Thanks.
– saadya
Mar 21 at 18:57
add a comment |
On sheet1 there is a submit button which runs a script and moves data into sheet2.
I'm 'timestamping' the move (under certain conditions to prevent overwriting, and pointless timestamps), however with the current script—
Issue (1): onEdit only takes place if I manually make an edit on sheet2 (=sheet2 is active).
RESOLVED! (See comments) Issue (2): onEdit won't restrict to sheet2, and will happen as well on sheet1.
function onEdit()
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
if( sheet.getName() == "sheet2" )
var activecell = sheet.getActiveCell();
if( activecell.getColumn() == 2 )
var pastecell = activecell.offset(0, -1);
if( pastecell.getValue() === '' & activecell.getValue() != '' )
pastecell.setValue(new Date()).setNumberFormat('YY-MM-DD HH:mm:ss');
Anyone know how two fix this?
Your help and insight is much appreciated!
javascript google-apps-script google-sheets
On sheet1 there is a submit button which runs a script and moves data into sheet2.
I'm 'timestamping' the move (under certain conditions to prevent overwriting, and pointless timestamps), however with the current script—
Issue (1): onEdit only takes place if I manually make an edit on sheet2 (=sheet2 is active).
RESOLVED! (See comments) Issue (2): onEdit won't restrict to sheet2, and will happen as well on sheet1.
function onEdit()
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
if( sheet.getName() == "sheet2" )
var activecell = sheet.getActiveCell();
if( activecell.getColumn() == 2 )
var pastecell = activecell.offset(0, -1);
if( pastecell.getValue() === '' & activecell.getValue() != '' )
pastecell.setValue(new Date()).setNumberFormat('YY-MM-DD HH:mm:ss');
Anyone know how two fix this?
Your help and insight is much appreciated!
javascript google-apps-script google-sheets
javascript google-apps-script google-sheets
edited Mar 21 at 19:05
saadya
asked Mar 21 at 18:05
saadyasaadya
85
85
ISSUE (2) RESOLVED! By simply changing—var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
to:var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet
– saadya
Mar 21 at 18:45
It is absolutely intentional that edit triggers do not activate for programmatic edits. If you're editing programmatically, you can just call the desired function from your program already.
– tehhowch
Mar 21 at 18:50
@tehhowch Yup! Just realized that🤦♀️ Going to timestamp straight in the move function. Thanks.
– saadya
Mar 21 at 18:57
add a comment |
ISSUE (2) RESOLVED! By simply changing—var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
to:var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet
– saadya
Mar 21 at 18:45
It is absolutely intentional that edit triggers do not activate for programmatic edits. If you're editing programmatically, you can just call the desired function from your program already.
– tehhowch
Mar 21 at 18:50
@tehhowch Yup! Just realized that🤦♀️ Going to timestamp straight in the move function. Thanks.
– saadya
Mar 21 at 18:57
ISSUE (2) RESOLVED! By simply changing—
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
to: var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet
– saadya
Mar 21 at 18:45
ISSUE (2) RESOLVED! By simply changing—
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
to: var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet
– saadya
Mar 21 at 18:45
It is absolutely intentional that edit triggers do not activate for programmatic edits. If you're editing programmatically, you can just call the desired function from your program already.
– tehhowch
Mar 21 at 18:50
It is absolutely intentional that edit triggers do not activate for programmatic edits. If you're editing programmatically, you can just call the desired function from your program already.
– tehhowch
Mar 21 at 18:50
@tehhowch Yup! Just realized that🤦♀️ Going to timestamp straight in the move function. Thanks.
– saadya
Mar 21 at 18:57
@tehhowch Yup! Just realized that🤦♀️ Going to timestamp straight in the move function. Thanks.
– saadya
Mar 21 at 18:57
add a comment |
1 Answer
1
active
oldest
votes
So after reading up🤦♀️ and @tehhowch insight of the following—
https://developers.google.com/apps-script/guides/triggers/
Script executions and API requests do not cause triggers to run. For
example, calling Range.setValue() to edit a cell does not cause the
spreadsheet's onEdit trigger to run.
Resolved by simply running the timestamp in the original move function, like so—
function move()
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
var source_range = source.getRange(3, 15, 1, 6).getValues();
var target = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
var target_range = target.getRange(target.getLastRow() + 1, 2, 1, 6);
target_range.setValues(source_range);
var datecell = target_range.offset(0, -1, 1, 1);
datecell.setValue(new Date()).setNumberFormat('YY-MM-DD HH:mm:ss');
var clearsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
clearsheet.getRange("J3:K4").clearContent();
clearsheet.getRange("B8:B25").clearContent();
clearsheet.getRange("H8:H9").clearContent();
clearsheet.getRange("H11").clearContent();
clearsheet.getRange("O7:P16").clearContent();
Sometimes you got to just think out loud. Hope this helps someone else.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55286670%2fgoogle-scripts-onedit-of-non-active-sheet%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
So after reading up🤦♀️ and @tehhowch insight of the following—
https://developers.google.com/apps-script/guides/triggers/
Script executions and API requests do not cause triggers to run. For
example, calling Range.setValue() to edit a cell does not cause the
spreadsheet's onEdit trigger to run.
Resolved by simply running the timestamp in the original move function, like so—
function move()
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
var source_range = source.getRange(3, 15, 1, 6).getValues();
var target = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
var target_range = target.getRange(target.getLastRow() + 1, 2, 1, 6);
target_range.setValues(source_range);
var datecell = target_range.offset(0, -1, 1, 1);
datecell.setValue(new Date()).setNumberFormat('YY-MM-DD HH:mm:ss');
var clearsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
clearsheet.getRange("J3:K4").clearContent();
clearsheet.getRange("B8:B25").clearContent();
clearsheet.getRange("H8:H9").clearContent();
clearsheet.getRange("H11").clearContent();
clearsheet.getRange("O7:P16").clearContent();
Sometimes you got to just think out loud. Hope this helps someone else.
add a comment |
So after reading up🤦♀️ and @tehhowch insight of the following—
https://developers.google.com/apps-script/guides/triggers/
Script executions and API requests do not cause triggers to run. For
example, calling Range.setValue() to edit a cell does not cause the
spreadsheet's onEdit trigger to run.
Resolved by simply running the timestamp in the original move function, like so—
function move()
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
var source_range = source.getRange(3, 15, 1, 6).getValues();
var target = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
var target_range = target.getRange(target.getLastRow() + 1, 2, 1, 6);
target_range.setValues(source_range);
var datecell = target_range.offset(0, -1, 1, 1);
datecell.setValue(new Date()).setNumberFormat('YY-MM-DD HH:mm:ss');
var clearsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
clearsheet.getRange("J3:K4").clearContent();
clearsheet.getRange("B8:B25").clearContent();
clearsheet.getRange("H8:H9").clearContent();
clearsheet.getRange("H11").clearContent();
clearsheet.getRange("O7:P16").clearContent();
Sometimes you got to just think out loud. Hope this helps someone else.
add a comment |
So after reading up🤦♀️ and @tehhowch insight of the following—
https://developers.google.com/apps-script/guides/triggers/
Script executions and API requests do not cause triggers to run. For
example, calling Range.setValue() to edit a cell does not cause the
spreadsheet's onEdit trigger to run.
Resolved by simply running the timestamp in the original move function, like so—
function move()
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
var source_range = source.getRange(3, 15, 1, 6).getValues();
var target = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
var target_range = target.getRange(target.getLastRow() + 1, 2, 1, 6);
target_range.setValues(source_range);
var datecell = target_range.offset(0, -1, 1, 1);
datecell.setValue(new Date()).setNumberFormat('YY-MM-DD HH:mm:ss');
var clearsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
clearsheet.getRange("J3:K4").clearContent();
clearsheet.getRange("B8:B25").clearContent();
clearsheet.getRange("H8:H9").clearContent();
clearsheet.getRange("H11").clearContent();
clearsheet.getRange("O7:P16").clearContent();
Sometimes you got to just think out loud. Hope this helps someone else.
So after reading up🤦♀️ and @tehhowch insight of the following—
https://developers.google.com/apps-script/guides/triggers/
Script executions and API requests do not cause triggers to run. For
example, calling Range.setValue() to edit a cell does not cause the
spreadsheet's onEdit trigger to run.
Resolved by simply running the timestamp in the original move function, like so—
function move()
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
var source_range = source.getRange(3, 15, 1, 6).getValues();
var target = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
var target_range = target.getRange(target.getLastRow() + 1, 2, 1, 6);
target_range.setValues(source_range);
var datecell = target_range.offset(0, -1, 1, 1);
datecell.setValue(new Date()).setNumberFormat('YY-MM-DD HH:mm:ss');
var clearsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
clearsheet.getRange("J3:K4").clearContent();
clearsheet.getRange("B8:B25").clearContent();
clearsheet.getRange("H8:H9").clearContent();
clearsheet.getRange("H11").clearContent();
clearsheet.getRange("O7:P16").clearContent();
Sometimes you got to just think out loud. Hope this helps someone else.
answered Mar 21 at 19:10
saadyasaadya
85
85
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55286670%2fgoogle-scripts-onedit-of-non-active-sheet%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
ISSUE (2) RESOLVED! By simply changing—
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
to:var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet
– saadya
Mar 21 at 18:45
It is absolutely intentional that edit triggers do not activate for programmatic edits. If you're editing programmatically, you can just call the desired function from your program already.
– tehhowch
Mar 21 at 18:50
@tehhowch Yup! Just realized that🤦♀️ Going to timestamp straight in the move function. Thanks.
– saadya
Mar 21 at 18:57