0

all! Newbie to Google Scripts, but I'm a fair-to-middlin' user of Tasker. Back in August I added a script to my spreadsheet to automatically sort two columns onEdit, based on a value in a cell. The spreadsheet is populated and the specific cell is changed from a Tasker plugin. In August, it worked fine! Everytime I added a row using Tasker, it populated the spreadsheet and immediatly sorted the spreadsheet without me needing to open the file.

Now it doesn't. I hadn't changed anything at the time, but I know any number of things could have changed - including Android, Tasker, Spreadsheet Update Plugin, or Google Scripts itself. Tasker would correctly populate the sheet and/or change the cell value, but the spreadsheet wouldn't sort. I'd open the sheet, the data would be added at the bottom of the sheet, but it wasn't sorted. I'd have to change the value of any cell to get it to sort while I had it open.

So, I searched the GS Developer pages, Stack Overflow, QnA, Google Groups page, even the Tasker Reddit and Google Group. In that process, I broke my sort all together and just now returned it to it's previous state: successfully populated from Tasker, but not sorting unless I open it.

I'm excited to get this working again. I'm very pleased with my automated system and want to share it with the different communities involved (Tasker, AutoApps, KWGT, and Google Drive). I can say to my phone that I spent money, it updates my expenses spreadsheet, which updates my phone widget to show me how much I've spent of my monthly budget. I also have a CookBook Tasker Project that, after selecting a recipe, will update my shopping list spreadsheet with the ingredients and puts it on my phone widget that would sort by the store I'm going to and will let me check off the items from the list. As it is, this shopping widget is useless now.

Has something changed? Is it no longer possible to trigger an onEdit when the sheet is changed from a third party? Here's the code I was using ... super simple because I do not know javascript, but it worked once and I'd love it to work again!

Thank you for your time!

function onEdit(e){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var storepicked = sheet.getRange("H1").getValue();
{
  sheet.sort(7,false);
}
if (storepicked == 1) {  
   sheet.sort(4);

}else if (storepicked == 2) {
   sheet.sort(5);

}else if (storepicked == 3) {
   sheet.sort(6);
}

{
  sheet.sort(7,false);
}
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Related: http://stackoverflow.com/questions/15232405/detect-user-inserting-row-or-column-in-a-google-spreadsheet-and-reacting-in-a-sc – Rubén Nov 15 '16 at 02:11
  • onEdit simple/installable triggers don't run on changes made by code. Maybe the changes were made on tasker. – Rubén Nov 15 '16 at 02:14
  • afaik onEdit triggers never worked when making changes outside of the sheets web api. – Zig Mandel Nov 15 '16 at 05:19

2 Answers2

0

The quickest fix would be to create a time based trigger to run every minute. Your script is small so you won't run into any quota limitations.

https://developers.google.com/apps-script/guides/triggers/installable#managing_triggers_manually

To manually create an installable trigger through a dialog in the script editor, follow these steps:

From the script editor, choose Resources > Current project's triggers.

Click the link that says: No triggers set up.

Click here to add one now.

Under Run, select the name of function you want to trigger.

Under Events, select either Time-driven or the Google App that the script is bound to (for example, From spreadsheet).

Select and configure the type of trigger you want to create (for example, an Hour timer that runs Every hour or an On open trigger).

Optionally, click Notifications to configure how and when you will be contacted by email if your triggered function fails. Click Save.

Community
  • 1
  • 1
utphx
  • 1,287
  • 1
  • 8
  • 19
  • Thanks for the suggestion, @utphx. I followed a related link shared by another user which, while not providing the answer, gave me a few more things to try. I got it to work after all! Instead of using a time based trigger, or an onEdit trigger, as I had been, the onChange trigger worked, but only after I deleted and re-typed my functions. Thanks again! – C Davis Nov 16 '16 at 00:35
0

Create a new script file Type out your function. You may be able to copy/paste, I didn't try it. Install a trigger From Spreadsheet, onChange. Save!