Preview:
// Replace 'YOUR_FORM_ID' with the ID of your Google Form
var form = FormApp.openById('1anUG2PmvXTIec9QycnZXEWFhDW8sAeDBgnQu9mefdo4');

// Load submission counter from Script Properties
var scriptProperties = PropertiesService.getScriptProperties();
var submissionCounter = parseInt(scriptProperties.getProperty('submissionCounter')) || 0;

function onFormSubmit(e) {
  var response = e.response;
  var itemResponses = response.getItemResponses();
  var recipientEmail = '';
  var generateSerialNumber = true; // Default to true, assuming serial number should be generated
  var fileIds = []; // Initialize array to store file IDs
  
  // Check the response for the specific question that determines whether to generate a serial number or not
  for (var i = 0; i < itemResponses.length; i++) {
    var itemResponse = itemResponses[i];
    if (itemResponse.getItem().getTitle() === 'FORM SUBMISSION TYPE') { // Adjust this to the title of the question that determines HR type
      if (itemResponse.getResponse() === 'CORPORATE HR') {
        generateSerialNumber = false; // If Corporate HR is selected, do not generate serial number
      }
    }
    if (itemResponse.getItem().getTitle() === 'TICKETS  OR DOCUMENTS') { // Adjust this to the title of the file upload question
      fileIds.push(itemResponse.getResponse()); // Get the file ID of the uploaded file
    }
  }
  
  // Incrementing the submission counter if needed
  if (generateSerialNumber) {
    submissionCounter++;
  }
  
  // Extracting the form data and formatting as HTML table
  var formData = '<table border="1">';
  
  // Adding serial number to the table if needed
  if (generateSerialNumber) {
    formData += '<tr><td><strong>Serial Number</strong></td><td>' + submissionCounter + '</td></tr>';
  }
  
  for (var i = 0; i < itemResponses.length; i++) {
    var itemResponse = itemResponses[i];
    formData += '<tr><td><strong>' + itemResponse.getItem().getTitle() + '</strong></td><td>' + itemResponse.getResponse() + '</td></tr>';
    if (itemResponse.getItem().getTitle() === 'EMAIL OF THE EMPLOYEE') { // Change 'Email Address' to the title of your email question
      recipientEmail = itemResponse.getResponse();
    }
  }
  formData += '</table>';
  
  if (recipientEmail !== '') {
    // Formatting the email content in HTML
    var htmlBody = '<html><body>';
    htmlBody += '<h1>New Form Submission</h1>';
    htmlBody += formData;
    if (fileIds.length > 0 && !generateSerialNumber) { // Include file download links if uploaded by Corporate HR
      htmlBody += '<p>Download Tickets/Documents:</p>';
      for (var j = 0; j < fileIds.length; j++) {
        var downloadUrl = getDownloadUrl(fileIds[j]);
        htmlBody += '<p><a href="' + downloadUrl + '">File ' + (j + 1) + '</a></p>';
      }
    }
    htmlBody += '</body></html>';
    
    // Subject with serial number if generated
    var subject = generateSerialNumber ? 'New Form Submission - Serial Number: ' + submissionCounter : 'New Form Submission';
    
    // Sending the email
    MailApp.sendEmail({
      to: recipientEmail,
      subject: subject,
      htmlBody: htmlBody
    });
  }
  
  // Store updated submissionCounter in Script Properties if needed
  if (generateSerialNumber) {
    scriptProperties.setProperty('submissionCounter', submissionCounter);
  }
}

// Function to get download URL of a file from Google Drive
function getDownloadUrl(fileId) {
  var file = DriveApp.getFileById(fileId);
  return file.getDownloadUrl();
}

// Install a trigger to run on form submission
function installTrigger() {
  ScriptApp.newTrigger('onFormSubmit')
      .forForm(form)
      .onFormSubmit()
      .create();
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter