为什么“提交”按钮对某些用户不起作用

时间:2020-02-24 11:50:49

标签: google-apps-script

我已经在Google应用脚本中创建了一个工具,该工具运行正常。突然之间,某些用户无法使用“提交”按钮。请参阅以下我的表单代码:

<div id="confirm"></div>
<div id="myBtn">VL Applicants Count>></div>
<form id="logForm" class="form-style-1">
  <label>Request Date <span class="required">*</span></label>
  <input type="text" id="datepicker" name="LoggedDate" class="field-long" placeholder="Date of VL"
    onkeypress="return false;" />
  <label>Reason of Leave <span class="required">*</span></label>
  <textarea id="rol" name="reason" class="field-long field-textarea"></textarea>

  <input type="text" id="timeStamp" name="TimeStamp" readonly />
  <input type="text" id="tNum" name="TcktNum" readonly />

  <input type="submit" value="Submit" id="submit-form" class="login100-form-btn"
    onclick="google.script.run.withSuccessHandler(formSubmitted) .writeForm(this.parentNode); return false;" />
</form>

<script>
  function formSubmitted(status) {

    document.getElementById('confirm').innerHTML = status;
  }
</script>

我已经更新了我的帖子,并添加了code.gs中所需的代码以运行“提交”按钮。

code.gs

function writeForm(form) { 

  try {  
    var email = Session.getEffectiveUser().getEmail();
    var self = ContactsApp.getContact(email);
    var TimeStamp = form.TimeStamp;
    var dovl = form.LoggedDate;
    var rovl = form.reason;
    var ldap = Session.getEffectiveUser().getUsername();
    var ReqNum = form.TcktNum;
    var stat = "Pending";
    var vltype = "Whole Day";
    var quote = '"';
    var TcktCreator = Session.getEffectiveUser().getEmail(); 

    var ss = SpreadsheetApp.openById('1_BuyTaupXC-D-BbLEneWlEyuv2XSKm-xCCjLRi5gf1U');

    var sheet = ss.getSheetByName("VL Request");
    var newRow = sheet.getLastRow()+1;//go to the first blank row
    var valLdap = 'Please complete the required Fields. <br>';
    var dateapplied = 'Date already applied<br>';
    //writes the form data to the spreadsheet
    var data = SpreadsheetApp
        .openById('1_BuyTaupXC-D-BbLEneWlEyuv2XSKm-xCCjLRi5gf1U')
        .getSheetByName("VL Request")
        .getDataRange()
        .getValues();
    var vldate = [5];
    var curruser = [2];
    for (var i = 1; i < data.length; i++) {
        var vlcheckdate = data[i][vldate];
        var monthcount = vlcheckdate.getMonth()+1;
        var datecount = vlcheckdate.getDate();
      if(monthcount < 10) {
        var formattedMonth = '0' + (vlcheckdate.getMonth()+1);
      }
      else{
        var formattedMonth = (vlcheckdate.getMonth()+1);
      }

      if(datecount < 10) {
        var formattedDate = '0' + vlcheckdate.getDate();
      }
      else{
        var formattedDate = vlcheckdate.getDate();
      }


      var formattedDateVL = formattedMonth + '/' + formattedDate + '/' + vlcheckdate.getYear();

      if((formattedDateVL == dovl) && (data[i][curruser] == ldap)){
        var checker = "1";
        break;
      }
    }

    if(dovl == "" || rovl == ""){
      return valLdap; 
    }

    if(checker == "1") {
     return dateapplied; 
    }

    else{

      var data = SpreadsheetApp
        .openById('1_BuyTaupXC-D-BbLEneWlEyuv2XSKm-xCCjLRi5gf1U')
        .getSheetByName("Users")
        .getDataRange()
        .getValues();
      var user = [0];
      var lob = [4];
      var tlldap = [5];
      var tlname = [7];
      var name = [2];
      var pocldap = [11];
      var omldap = [8];
      for (var j = 1; j < data.length; j++) { 
   if (data[j][user] === ldap){
   var tlLdap = data[j][tlldap];
   var fname = data[j][name];
   var tlName = data[j][tlname];  
   var lane = data[j][lob];
   var poc = data[j][pocldap];
     var om = data[j][omldap];
   }
   }

    var range = sheet.getRange(newRow, 1);    
    range.setValue(TimeStamp);
    range = sheet.getRange(newRow, 2);
    range.setValue(ReqNum);
    range = sheet.getRange(newRow, 4);
    range.setValue(tlLdap);   
    range = sheet.getRange(newRow, 5);
    range.setValue(vltype);
    range = sheet.getRange(newRow, 6);
    range.setValue(dovl);
    range = sheet.getRange(newRow, 7);
    range.setValue(rovl);
    range = sheet.getRange(newRow, 8);
    range.setValue(fname);
    range = sheet.getRange(newRow, 9);
    range.setValue(tlName);
    range = sheet.getRange(newRow, 10);
    range.setValue(lane);  
    range = sheet.getRange(newRow, 3);
    range.setValue(ldap);
    range = sheet.getRange(newRow, 13);
    range.setValue(stat);
    range = sheet.getRange(newRow, 16);
    range.setValue(poc);
    range = sheet.getRange(newRow, 17);
    range.setValue(om);  

    }


    var spreadsheet = SpreadsheetApp.getActive();
  var validation_file = SpreadsheetApp.openById("1_BuyTaupXC-D-BbLEneWlEyuv2XSKm-xCCjLRi5gf1U");
  var logged_act_sheet = validation_file.getSheetByName("VL Request"); 

   //an array of confirmation messages that will display as HTML 
    var confirmationMessage = ['<B>Time Stamp:</B> ' + TimeStamp +
                               '<br><B>Request ID:</B> ' + ReqNum +
                               '<br><B>Name:</B> ' + ldap +
                               "<br><B>Date of VL:</B> " + dovl + 
                               "<br><B>Reason of VL:</B> " + rovl +
                               "<br><B>Status:</B> " + stat +
                               '<br><br><B><a href="https://script.google.com/macros/s/AKfycbwtc_JY2ddOs0EdOmYvJiaQWbEfKmTdzqIN4Oq4SG0/dev">Refresh page>></a><B><br><br>' 
                              ];
    var len = confirmationMessage.length-1;
    Logger.log('len= ' + len);
    var i = Math.floor(Math.random() * len);//randomizes from the array

    return confirmationMessage[i]; //displays randomized message

  } 

  catch (error) {

    return error.toString();
  }
}

我实际上是在考虑Google是否有更新,表明我的脚本可能无法为某些类型的用户运行。

0 个答案:

没有答案