How do you open a Google form from a Custom Menu Item

旧街凉风 提交于 2020-01-06 19:49:15

问题


I am brand new to Google Script and I am trying to create a Google Sheet to manage the creation of Quotes....I have created a form that will capture the Quote details and I want the user to be able to click on a Menu item at the top of the Sheet to "Create New Quote" which will open the Form.

What command can I use in place of the following when creating the Menu Item so that is will Open the Form....do I need to refer to the Form ID anywhere ?

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  // Or DocumentApp or FormApp.
  ui.createMenu('Quote Generator Menu')
      .addItem('Create New Quote', 'menuItem1')
      .addItem('Update Lists', 'updateLists')
      .addSeparator()
      .addSubMenu(ui.createMenu('Reporting')
          .addItem('Dashboard', 'menuItem2'))
      .addToUi();
}

function menuItem1() {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
     .alert('You clicked Create New Quote');
}

function menuItem2() {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
     .alert('You clicked Dashboard');
}

回答1:


One quick and dirty way. Upon menu click:

  1. Create a UI app.
  2. Create a hyperlink to the published form, instructing user to click link to add a new quote.
  3. Add link to UI app.
  4. Display UI app.

Example:

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Quote Generator Menu')
    .addItem('Create New Quote', 'showUrl')
    .addToUi();
}

// http://stackoverflow.com/questions/26815296
function showUrl(){
  var FORM_URL = "ENTER_FORM_URL_HERE";
  var app = UiApp.createApplication().setHeight(50).setWidth(200);
  app.setTitle("Submit New Quote");
  var link = app.createAnchor('Click to here to submit a new quote', FORM_URL);
  app.add(link);  
  var doc = SpreadsheetApp.getActive();
  doc.show(app);
}

Screenshot of UI prompt that pops up after clicking the menu:



来源:https://stackoverflow.com/questions/26815296/how-do-you-open-a-google-form-from-a-custom-menu-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!