Permissions at google App Scripts

1 view
Skip to first unread message

ECFA Ignacio Pyznar

unread,
6:14 AM (2 hours ago) 6:14 AM
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,
6:21 AM (2 hours ago) 6:21 AM
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.
Reply all
Reply to author
Forward
0 new messages