0

I have been searching high and low and can not find a concrete answer. Some questions say yes others say no. In the case, I have a script I want to run that creates a custom menu/menu item that runs another script. I have this installed as an installable trigger set to run onOpen. This works marvelously for me or anyone else logged into google. Using incognito or not being logged in not so much. I have also attempted doing this via web app publishing using the "execute the app as" "Me" and "who has access to the app" "Anyone, even anonymous". This again works great for me and anyone logged in not so much for incognito or people not logged in. I am pretty much at the end of my rope trying to make heads or tails of this.

/*
Global
*/
var width = 1000;
var height = 700;

/**
 * Creates a trigger for when a spreadsheet opens.
 */
function createSpreadsheetOpenTrigger() {
  var ss = SpreadsheetApp.getActive();
  ScriptApp.newTrigger('onOpen')
      .forSpreadsheet(ss)
      .onOpen()
      .create();
}

function onOpen() {
  SpreadsheetApp.getUi().createMenu('Freight Form').addItem('Freight Form', 'freight').addToUi();
}

function freight(){
  
  var hs = HtmlService.createTemplateFromFile('ModalDialog');
  hs.width = width;
  hs.height = height;
  hs.publishedUrl = SpreadsheetApp.openById("spreadsheetID*").getFormUrl();https://docs.google.com/forms/d/e/spreadsheetID*/viewform?usp=sf_link
  var userInterface = hs.evaluate()
  .setWidth(width)
  .setHeight(height);
  SpreadsheetApp.getUi().showModalDialog(userInterface, 'Form');
}

function getSize(type){
  if(type === 'width')
    return width - 20;
  if(type === 'height')
    return height - 20;
  return 600;
}
Marios
  • 26,333
  • 8
  • 32
  • 52
  • [Edit] to use proper tags to reach the right audience. – TheMaster Sep 20 '19 at 07:09
  • See the following links: https://stackoverflow.com/questions/27173605/google-app-script-allowing-access-for-anonymous-users https://stackoverflow.com/questions/26318755/scripts-not-working-for-anonymous-users-google-spreadsheet, https://developers.google.com/apps-script/guides/services/authorization – ziganotschka Sep 20 '19 at 13:44
  • @ziganotschka While I have read all of those already I may be ignorant as to their meaning. It sounded to me that if I published the Web App under the ("execute the app as" "Me" and "who has access to the app" "Anyone, even anonymous".) then it should run as me even for anonymous users. Serge insas states that "The installable onEdit will work since it works as you, not the unlogged user. " I have tried both onedit and onopen to no avail. I can post the code if that would help. – user1324637 Sep 20 '19 at 14:43
  • 1
    Those posts point out that the WebApp will work only frontend for anonymous users. You won't have access to SpreadsheetApp.getUi() - which you need to create a menu. – ziganotschka Sep 20 '19 at 14:56
  • Thank you for the clarification. So it sounds like what I am wanting to do is not doable via google applications. – user1324637 Sep 20 '19 at 15:20
  • What is it that you're trying to do? – TheMaster Sep 20 '19 at 15:35
  • I was trying to run a script that users that were not logged in could use. As you explained that is defineteively not possible. – user1324637 Sep 22 '19 at 01:01

0 Answers0