Permissions at google App Scripts

453 views
Skip to first unread message

ECFA Ignacio Pyznar

unread,
Jul 19, 2024, 6:14:29 AM7/19/24
to Google Apps Script Community
 Hello, I have this code that isn't working for me. The idea is that when I open the Google Sheet, this code should execute using the onOpen function to create 3 triggers for my 3 scripts. The problem lies in some permissions when the createTriggers function is called, which throws the following error: 'You do not have permission to call ScriptApp.newTrigger. Required permissions: http://www.googleapis.com' (a link that doesn't go anywhere).  

  Here's the code:

function onOpen() {
  var properties = PropertiesService.getUserProperties();
  var triggersCreated = properties.getProperty('triggersCreated');
 
  if (triggersCreated === 'true') {
    // Show message if triggers already exist
    SpreadsheetApp.getUi().alert('Production has already been initiated previously.');
  } else {
    // Create triggers if they don't exist
    createTriggers();
    // Mark triggers as created
    properties.setProperty('triggersCreated', 'true');
  }
}

function createTriggers() {
  var spreadsheetId = SpreadsheetApp.getActiveSpreadsheet().getId();
 
  ScriptApp.newTrigger('onEdit2')
    .forSpreadsheet(spreadsheetId)
    .onEdit()
    .create();
 
  ScriptApp.newTrigger('onEdit3')
    .forSpreadsheet(spreadsheetId)
    .onEdit()
    .create();
 
  ScriptApp.newTrigger('onEdit4')
    .forSpreadsheet(spreadsheetId)
    .onEdit()
    .create();
}

If anyone knows how to solve this permission issue, it would be greatly appreciated. Thank you very much!   


Andrew Roberts

unread,
Jul 19, 2024, 6:21:35 AM7/19/24
to google-apps-sc...@googlegroups.com
onOpen will need to be run as an "installable" trigger, rather than a "simple" one as it is by default. 

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/412226bd-eb61-4d0f-a8e5-f21044f69e83n%40googlegroups.com.

George Ghanem

unread,
Jul 19, 2024, 8:54:39 PM7/19/24
to google-apps-sc...@googlegroups.com

The onOpen is a simple trigger. You are not allowed to make any calls to external services like creating a trigger. All you can do is manipulate the spreadsheet itself.


Reply all
Reply to author
Forward
0 new messages