0
votes

The HTML sidebar get user input and save it in sheet:

  1. with sheet's owner, it works fine (the data from sidebar are correctly saved in the sheet)
  2. with others sheet editors the data from sidebar is NOT been saved in the sheet.

Owner and users at same domain Apps Script Dashboard shows NO error

I would be very grateful for any help on how I can fix this issue.

SIDEBAR SOURCE:

<!DOCTYPE html>
<html>
<!-- Style should be in the head -->
<style>
    .info {
        margin: 5px;
        width: 95%;
        padding: 2px;
        font-size: 14px;
        font-weight: bold;
    }
    .msg {
        margin: 5px;
        width: 95%;
        padding: 2px;
        font-size: 13px;    
    }

    .container,
    .buttons {
        margin: 5px;
        width: 95%;
        padding: 2px;
        font-size: 13px;
    }
</style>

<head>
    <base target="_top">
    <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
</head>

<body>
    <div class="msg"> 
      <p align="justify">Marque todos os motivos que levaram ao indeferimento do requerimento</p>
    </div>
    
    <div class="info">
      <p id="stdname"></p>
      <p id="stamp"></p>
      <p id="applied"></p>
      <p id="eRange"></p>
    </div>
    
    <div class="container">
      <?!=rngValid?>
    </div>
    
    <div class="buttons">
      <p>
        <button class="action" id="action" onclick="saveReasons();">Salvar motivos</button>
      </p>
      <br>             
    </div>
    <!-- These should be in the head. They should be there prior to page loading-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.rawgit.com/mdehoog/Semantic-UI/6e6d051d47b598ebab05857545f242caf2b4b48c/dist/semantic.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.min.js"></script>
    
    <script>
      var stamp    = <?= stamp ?>;
      var to       = <?= to ?>;
      var subject  = <?= subject ?>;
      var stdName  = <?= stdName ?>;
      var apply    = <?= apply ?>;      
      var eRange   = <?= eRange ?>;
      
      document.getElementById("stdname").innerHTML = stdName;
      document.getElementById("stamp").innerHTML   = stamp;
      document.getElementById("applied").innerHTML = apply;
      document.getElementById("eRange").innerHTML  = eRange;

      
      function saveReasons() {
        var selected = [];
        //get all checkboxes
        var checkboxes = document.getElementsByClassName("ui.checkbox");
        console.log("checkboxes length: "+ checkboxes.length);
        console.log("checkboxes: "+ checkboxes);
            $("input:checkbox[name=sel]:checked").each(function() {
              selected.push($(this).val());
              $(this).prop( "checked", false ); 
            })

        console.log("selected: "+ selected);
        console.log("eRange: "+ eRange);
        
        google.script.run
          .withFailureHandler(() => {console.log("Error running script")})
          .process(selected,stdName, apply, eRange);
      }

    </script>
</body>

</html>

DEV TOOLS CONSOLE:

Net state changed from IDLE to BUSY           386795301-warden_bin_i18n_warden.js:67
Net state changed from BUSY to IDLE           userCodeAppPanel:36
Error running script
1
So it looks like you have a failure in gs function process. - Cooper
Sounds like an authentication issue. - Cooper
Can you provide your code,gs part? Does the function run on trigger? Do you slect "show sidebar" from the custom menu? - ziganotschka
Hi Cooper, tks for your reply. I think so; I was accessing as anonymous. Hi ziganotschka, tks for your reply. No, there's no trigger on process(). Sidebar runs from an onEdit trigger. What I did: - I accessed like owner by a NON anonymnous ; - Apps Script Dashboard then shows some erros (but incredible that these erros did not affected that owner could save data). - I corrected the erros and now everthing is working fine. Sorry for any inconvenience - jcom

1 Answers

0
votes

On your client-side code there is the following

google.script.run
      .withFailureHandler(() => {console.log("Error running script")})
      .process(selected,stdName, apply, eRange);

The problem with the above code is that it give very low help to debug the main problem.

To get a meaningful error message replace

.withFailureHandler(() => {console.log("Error running script")})

to

.withFailureHandler((error) => {console.log('%s, %s',error.message, error.stack)})