Can the Google Spreadsheet Script library contain a user dialog?

Are there any restrictions on what might be in the Apps Script library that Google spreadsheets will use? In particular, can a library include an HTML dialog?

I created a Script table that adds a menu item to present a dialog box to the user. It uses   HtmlService.createHtmlOutputFromFile('mappingForm').setSandboxMode(HtmlService.SandboxMode.IFRAME)

as described at https://developers.google.com/apps-script/guides/html/communication . HTML file contains HTML, CSS and JavaScript with jQuery. It uses google.script.runto populate the dialog box with data from the spreadsheet and submit the form to it.

All this works fine in the source table.

I need several spreadsheets to use the same code, so I try to follow the general idea of Google Spreadsheet Scripts, shared by spreadsheets (not libraries) . have a Script wizard with a spreadsheet template and multiple copies.

I followed the instructions of https://developers.google.com/apps-script/guide_libraries to create a library from the source spreadsheet. When another spreadsheet uses the library, I can get a dialog box to be displayed, but all the callbacks to the server (either to populate the dialog box or to submit the form) fail with an error, caught on the browser side google.script.run.withFailureHandleras an object Errorwith properties:

message: "We're sorry, a server error occurred. Please wait a bit and try again."
name: "ScriptError"

Logger Script, , , . Script Execution Transcript :

[14-12-27 19: 38: 05: 340 PST]

[14-12-27 19: 38: 05: 372 PST] : , . . [0.0 ]

, - , script.

:

  • - -, .
  • .
  • .

.

+4
1

, HTML-, .

  • script HTML script . Project key > .... , .

  • script , , , , .

  • HTML ( ), , , JavaScript.

  • , : > script editor... > .... " " , , . > , . script . SignupFormResponsesSheet.

  • script -, , , HTML. onOpen(), HTML,

function onOpen() {
    SignupFormResponsesSheet.onOpen();
}

function showMappingForm() {
    SignupFormResponsesSheet.showMappingForm();
}

function showSubmitForm() {
    SignupFormResponsesSheet.showSubmitForm();
}
Hide result
  1. HTML- , , - , , , , script , . - , . .

function runSignupFormResponseFunction(funcName, varargs) {
  return SignupFormResponsesSheet[funcName].apply(this,
    Array.prototype.slice.call(arguments, 1));
}
Hide result
  1. - , 3 , JavaScript HTML google.script.run runSignupFormResponseFunction . , , getRangeLabels getColumnExamples ( ),

google.script.run
  .withFailureHandler(showError)
  .withSuccessHandler(function(ranges) {
    loadRanges(ranges);
    // once ranges are loaded, load columns
    google.script.run
      .withSuccessHandler(loadColumns)
      .withFailureHandler(showError)
      .runSignupFormResponseFunction("getColumnExamples");
  })
  .runSignupFormResponseFunction("getRangeLabels");
Hide result

. , , .

+3

Source: https://habr.com/ru/post/1569180/


All Articles