New to google apps script and Javascript

42 views
Skip to first unread message

Bafana Kgotlello

unread,
May 23, 2024, 3:09:28 AMMay 23
to Google Apps Script Community
Greetings everyone, I've been trying to create a complaints management system (using Google Forms, Google Sheets and Apps Script).
I already have a google form attached to the sheet and the apps script. But when I deploy the app and press on the login button. the form does not appear and instead I get the "Google Drive, Sorry Unable to open file at present"
these are my codes for the project

CodeNumber1
function doGet() {
  return HtmlService.createHtmlOutputFromFile("login");
}

function login(email, password) {
  // Authenticate user using Google Accounts or other methods
  // ...
  // If authenticated, return true
  return true;
}

function doPost(e) {
  var email = e.parameters.email;
  var password = e.parameters.password;
  if (login(email, password)) {
    // Redirect to the form page
    return HtmlService.createHtmlOutputFromFile("form");
  } else {
    // Display an error message
    return HtmlService.createHtmlOutput("Invalid credentials. Please try again.");
  }
}

CodeNumber2

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>

  <script src= "1wIXTcs9PS3BkjhK702zvFVXacHmepkJjqZI7BSRMWnJraDoW4Rag1dD2"></script>
  <body>
    <h1>Login</h1>
    <form>
      <input type="email" id="email" placeholder="Email">
      <input type="password" id="password" placeholder="Password">
      <input type="submit" value="Login">
    </form>
    <script>
      function login() {
        var email = document.getElementById("email").value;
        var password = document.getElementById("password").value;
        // Authenticate user using Google Accounts or other methods
        // ...
        // If authenticated, redirect to the form page
        window.location.href = "https://docs.google.com/forms/d/1EOGogYZd7JNRqTee2D1EB7gToT3d1USlQ2TWFTE-bZw/edit";
        return false;
      }

      document.getElementByld("Submit").addEventListener("click",login);
    </script>
  </body>
</html>

CodeNumber3

function onFormSubmit(e) {
  var formResponse = e.response;
  var complaintDescription = formResponse.getQuestion(4).getResponse();
  var category = formResponse.getQuestion(5).getResponse();
 
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.appendRow([new Date(), formResponse.getRespondentEmail(), "", "", category, complaintDescription, "", "", ""]);
}


function assignComplaint(assignee) {
  var sheet = SpreadsheetApp.getActiveSheet();
  var complaintRow = sheet.getActiveCell().getRow();
  sheet.getRange(complaintRow, 7).setValue(assignee);
}

function resolveComplaint(resolution) {
  var sheet = SpreadsheetApp.getActiveSheet();
  var complaintRow = sheet.getActiveCell().getRow();
  sheet.getRange(complaintRow, 8).setValue(resolution);
}

function onEdit(e) {
  var sheet = SpreadsheetApp.getActiveSheet();
  var editedCell = sheet.getActiveCell();
 
  // Call the assignComplaint or resolveComplaint function based on the edited cell
  if (editedCell.getColumn() == 7) { // Assuming the "Assigned To" column is the 7th column
    assignComplaint(editedCell.getValue());
  } else if (editedCell.getColumn() == 8) { // Assuming the "Resolution" column is the 8th column
    resolveComplaint(editedCell.getValue());
  }
}
Reply all
Reply to author
Forward
0 new messages