Apr 20, 2020

My Apps Script doesn't seem to run for other people

This weekend, I used Apps Script for the first time while logged in to my company G Suite account.  I am not a programmer.  I started with a Google Sheet, selected "Tools -> script editor", wrote (mostly borrowed from online forums) several functions (over 300 lines total), and saved them to a new project called  "Test_Sheet_Functions", which only has one tab on the left side bar named "Code.gs".   (I'm not sure if it saved to the Sheet or in some global area under my account.).  I then created and added images (buttons) to the Google Sheet, assigned functions to them, and test them out.  The longest one took less than 5 seconds, and they all worked.

I shared the Sheet with two co-workers (their work accounts, under the same G Suite company domain).  When they click on any of the buttons, they see the message "Running Script" with the options to cancel or dismiss; however, nothing happens. (They waited about 30 seconds.)

Why does it work for me but not for them?  

Do I need to share the Project separately from sharing the Sheet?  Is there some permissions setting under their account that they have to enable/approve?
Locked
Informational notification.
This question is locked and replying has been disabled.
Community content may not be verified or up-to-date. Learn more.
Recommended Answer
Apr 20, 2020
Hi Mark,
 
I took a quick look. Cannot see anything in the code that would prevent others from running the functions. Perhaps they did not complete the authorization dialog box that pops up the first time they click a button? It takes several steps to grant the authorization, and none of the functions will get run until they have completed the process.
 
Please find below a streamlined version of myStartNewOrderFunction. To learn scripting, go to the Beginner's Guide, the Extending Google Sheets page, javascript.info, Codecademy and Mozilla Developer Network.
 
Cheers --Hyde
 
------------
/**
* Creates new lookup and order sheets by duplicating the Item_Lookup and New_Order sheets.
*
* @OnlyCurrentDoc
*/
function myStartNewOrderFunction() {
  var ss = SpreadsheetApp.getActive();
  var myRequestor = Session.getActiveUser().getEmail();
  var myDate = Utilities.formatDate(new Date(), ss.getSpreadsheetTimeZone(), "yyyy-MM-dd' 'HH:mm:ss");
  // make a copy of the lookup sheet
  var myLookupCopyName = myDate + "_Lookup";
  var itemLookupTemplateSheet = ss.getSheetByName('Item_Lookup');
  var itemLookupSheet = itemLookupTemplateSheet.copyTo(ss).setName(myLookupCopyName);
  itemLookupSheet.getRange(1, 25).setValue(myDate);
  itemLookupSheet.getRange(1, 26).setValue(myLookupCopyName);
  // make a copy of the order sheet
  var newOrderTemplateSheet = ss.getSheetByName('New_Order');
  var newOrderSheet = newOrderTemplateSheet.copyTo(ss).setName(myDate);
  newOrderSheet.getRange(1, 25).setValue(myDate);
  newOrderSheet.getRange(1, 26).setValue(myLookupCopyName);
  newOrderSheet.getRange(6, 6).setValue(myRequestor);
  // go to the new sheet
  newOrderSheet.activate();
}
Original Poster Mark Taylor 2729 marked this as an answer
Helpful?
All Replies (7)
Recommended Answer
Apr 20, 2020
Hi Mark,
 
I took a quick look. Cannot see anything in the code that would prevent others from running the functions. Perhaps they did not complete the authorization dialog box that pops up the first time they click a button? It takes several steps to grant the authorization, and none of the functions will get run until they have completed the process.
 
Please find below a streamlined version of myStartNewOrderFunction. To learn scripting, go to the Beginner's Guide, the Extending Google Sheets page, javascript.info, Codecademy and Mozilla Developer Network.
 
Cheers --Hyde
 
------------
/**
* Creates new lookup and order sheets by duplicating the Item_Lookup and New_Order sheets.
*
* @OnlyCurrentDoc
*/
function myStartNewOrderFunction() {
  var ss = SpreadsheetApp.getActive();
  var myRequestor = Session.getActiveUser().getEmail();
  var myDate = Utilities.formatDate(new Date(), ss.getSpreadsheetTimeZone(), "yyyy-MM-dd' 'HH:mm:ss");
  // make a copy of the lookup sheet
  var myLookupCopyName = myDate + "_Lookup";
  var itemLookupTemplateSheet = ss.getSheetByName('Item_Lookup');
  var itemLookupSheet = itemLookupTemplateSheet.copyTo(ss).setName(myLookupCopyName);
  itemLookupSheet.getRange(1, 25).setValue(myDate);
  itemLookupSheet.getRange(1, 26).setValue(myLookupCopyName);
  // make a copy of the order sheet
  var newOrderTemplateSheet = ss.getSheetByName('New_Order');
  var newOrderSheet = newOrderTemplateSheet.copyTo(ss).setName(myDate);
  newOrderSheet.getRange(1, 25).setValue(myDate);
  newOrderSheet.getRange(1, 26).setValue(myLookupCopyName);
  newOrderSheet.getRange(6, 6).setValue(myRequestor);
  // go to the new sheet
  newOrderSheet.activate();
}
Original Poster Mark Taylor 2729 marked this as an answer
Apr 21, 2020
Both of them claim that there was no pop-up to grant authorization to/for the script.  
Regardless, there is no pop-up now.  How would they go about continuing/starting the authorization process?
Apr 21, 2020
Both of them claim that there was no pop-up to grant authorization to/for the script.
 
 
Hi Mark,

Are they opening the spreadsheet on a computer, or are they perhaps using the Sheets app on a phone or a tablet?
 
I am attaching a short script that should let you verify conclusively whether your users can execute scripts or not. Create a blank spreadsheet and paste the script in Tools > Script editor. This script does not need authorization. If the users do not see cell A1 incrementing when they open the spreadsheet, their platform does not execute scripts.
 
If this test script works for them, but they still cannot get buttons to work, you could try using a menu items instead of buttons to start your functions.
 
Cheers --Hyde
 
--------
/**
* Simple trigger that runs each time the user opens the spreadsheet.
*
* @OnlyCurrentDoc
* @param {Object} e The onOpen() event object.
*/
function onOpen(e) {
  var testCell = 'A1';
  var ss = SpreadsheetApp.getActive();
  var range = ss.getRange(testCell);
  var value = range.getValue();
  var incrementedValue = (Number(value) || 0) + 1;
  range.setValue(incrementedValue);
  ss.toast('onOpen ran fine. New value in cell ' + testCell + ' is ' + incrementedValue + '. The old value was ' + value + '.', 'Testing onOpen', -1);
}
 
Apr 22, 2020
The test sheet with the code you provided did work when the same user opened it.  Cell A1 incremented from 0 to 1.
You previously mentioned that she should have received a message to grant permission for my script to run.  
She claims that she did not get any such message.  Instead, the Google sheet says the script is running, but it never does anything.
This makes no sense.
Any thoughts?
false
16655570215160107470
true
Search Help Center
true
true
true
true
true
35
Search
Clear search
Close search
Main menu
false
false