0
votes

I've created a google sheets add-on for someone else, and they need other people in their Gsuite organization to be able to use the add-on as well. The add on worked as intended during testing and development, but when we published it, it would only work for the account that published it. When other's tried using it, it would not work properly. It had some functionality, but not others, and I'm unable to pinpoint what is happening.

I have been googling, following guides and experimenting for hours now and cannot figure this out. I believe I have added all the scopes needed, and enabled all the apis, but I am new to this so idk?

I'm sorry if this is a really vague and not very thought out question, but I really need help and don't really know where else to go. Any help is appreciated so much

[EDITED WITH CODE] The Add-on shows up in the marketplace and can be installed. It shows the menu and the sidebar, but no buttons actually work in the sidebar. I think its an issue with the add-on and publication of it, rather than an issue with the code itself, but I guess that's why I'm asking here... https://codepen.io/garrettarh/pen/abvgmKJ I get this error in the chrome console:

Uncaught     (string of numbers)-mae_html_user_bin_i18n_mae_html_user.js:54

I know it's not pretty lmao, but I'm new to Gsuite and App Script, just finding something that works. Optimization isn't really the priority atm.

[EDITED WITH SCOPES] enter image description here

[EDIT WITH WORKAROUND] I came across this question Uploading a file using an HtmlService form in Google Apps always causes "server error" and a stack trace

and someone suggested using STABLE as the runtime version instead of V8, and so far I believe this has fixed my issue. I'm not savvy enough to know exactly what was wrong.

1
Yeap, the question is very vague and chrome console could include error messages that are not related to you add-on. - Rubén
Do your add-on has a dynamic menu? Are you using simple or installable triggers? Does the add-ons users installing the add-on from the the spreadsheet add-ons menu or from the G Suite Marketplace? Does the add-on was installed by individuals or it was installed for the whole domain? - Rubén
Well I didn't get that error prior to publish. It shows up when press a button on my sidebar. (The button isn't the only functionality that is broken) The button then runs a Google script function. The add-on was published internally for a gsuite organization. The add-on has a menu. The add-on is being installed from the organization's gsuite marketplace add-ons menu, but it wasn't installed through the whole domain. - Garrett Smith
Well, when are you going share all of your code? - Cooper
mae_html_user_bin_i18n_mae_html_user.js is this file part of the Add on code? For others to help, it is usually necessary to see the code, or to be able to reproduce the error. With the info provided neither is possible. - Aerials

1 Answers

1
votes

I'm not sure if this will make any difference at all, but I changed the script in the HTML to:

<html>
  <head>
    <base target="_top">
    <link href="https://ssl.gstatic.com/docs/script/css/add-ons.css" rel="stylesheet">
    <style>
    #title {
    color: #54AE54 !important;
    font-size: 18px;
    padding: 6px;
    }
    #runScript {
    background: #54AE54 !important;
    color: #F1FFE7;
    margin: 20px;
    }

    body {
    background: white;
    text-align: center;
    }
    .outline {
    outline-style: double ;
    outline-color: #968E85 ;
    padding: 10px;
    }

    .smallH {
    margin-block-start: 0.8em;
    margin-block-end: 0.8em;
    }
    .range {
    width: 45%;
    display: inline-block;
    padding: 5px;
    }
    #classesRange:disabled {
    color: gray;
    }
    #emailRange:disabled {
    color: gray;
    }
    </style>
  </head>



  <body>
  <div class="outline">
    <h1 id="title">Course Choice ID Match</h1>
    <hr class='solid'>
    <h2>Input Sheet</h2>
    <select name="Input Sheet" id="inputSheetDD">
       <option value="" disabled selected hidden>Choose an input sheet</option>
       <? var sheets=SpreadsheetApp.getActive().getSheets(); ?>
       <? for (var i=0;i<sheets.length;i++) { ?>
       <option value=<?=sheets[i].getName()?>> <?= sheets[i].getName()?></option>
       <? } ?>
    </select>
    <? var sheets=SpreadsheetApp.getActive(); ?>
    <h2>Input Columns</h2>
    <div class="range">
    <h4>Email Columns</h4>
       <input type="text" placeholder="type cell range" id="emailRange" size="12"?>
       <h5 class="smallH">OR...</h5>
       <button id="emailButton">Get Selected Range</button>
    </div>
    <div class="range">
       <h4>Classes Columns</h4>
       <input type="text" placeholder="type cell range" id="classesRange" size="12"?>
       <h5 class="smallH">OR...</h5>
       <button id="classesButton">Get Selected Range</button>
    </div>
    <h2>Output</h2>
    <h5 class="smallH">Output Sheet Name</h5>
    <input type="text" placeholder="name output sheet" id="outputName">
    <h5 class="smallH">Creator ID</h5>
    <input type="text" placeholder="type creator ID #" id="creatorID">
    <button id="runScript">Run Script</button>
   </div>



    <script>
    function onSuccess(activeRange) {
       if (window.buttonClicked == 'classesButton') {
          classesRange.value = activeRange;
          classesRange.disabled = false;
       }
       if (window.buttonClicked == 'emailButton') {
          emailRange.value = activeRange;
          emailRange.disabled = false;
       }
    }

    window.onload = function() {
      var buttons = document.getElementsByTagName("button");

      console.log("buttons.length: " + buttons.length)

      for (var i = 0; i <= buttons.length; i += 1) {
        var thisBtn = buttons[i];

        if (!thisBtn) {
          return;
        }

        console.log('thisBtn.id: ' + thisBtn.id)
        var thisID = thisBtn.id;

        switch(thisID) {

          case 'classesButton':
            console.log('its classesButton')
            thisBtn.addEventListener("click", function() {
              window.buttonClicked = this.id;
              document.getElementById("classesRange").disabled = true;
              document.getElementById("classesRange").value = "working...";
              google.script.run.withSuccessHandler(onSuccess).getSelectedRange();
             })

             break;
            case 'emailButton':
              console.log('its emailButton')

              thisBtn.addEventListener("click", function() {
                window.buttonClicked = this.id;
                document.getElementById("emailRange").disabled = true;
                document.getElementById("emailRange").value = "working...";
                google.script.run.withSuccessHandler(onSuccess).getSelectedRange();
               })
              break;
            case 'runScript':
              console.log('its runScript')

              thisBtn.addEventListener("click", function() {
                window.buttonClicked = this.id;
                var inputSheet = document.getElementById('inputSheetDD').value;
                var emailRange = document.getElementById('emailRange').value;
                var classesRange = document.getElementById('classesRange').value;
                var outputName = document.getElementById('outputName').value;
                var creatorID = document.getElementById('creatorID').value
                google.script.run.interpret(inputSheet, emailRange, classesRange, outputName, creatorID);
                })
                break;
            }
         }

        };

    </script>
  </body>
</html>