I'd created a Google form for collecting data from users. In this form I'm going to ask the site name and want to replace it with Unique code.
I'd written the codes with google apps script for this which is given below but every time it generate new unique code and also replace previous one also.
function SendConfirmationMail(e) {
  try {
    var ss, bcc, sendername, subject, columns, username;
    var message, value, textbody, usermail, track, code;
    // This is your email address and you will be in the BCC
    bcc = Session.getActiveUser().getEmail();
    // This will show up as the sender's name
    sendername = "Support Team";
    // This is the submitter's Name
    username = e.values[1];
    // This is the submitter's email address
    usermail = e.values[2];
    // Custom subject for Google Docs emails
    subject = "Support Ticket";
    // Random Code for Google Docs emails
    ss = SpreadsheetApp.getActiveSheet();
    track = new Array();
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 10;
    var lastRow = ss.getLastRow()-1;
    var randomstring = '';
    for (var i=0; i<string_length; i++) {
      var rnum = Math.floor(Math.random() * chars.length);
      randomstring += chars.substring(rnum, rnum+1);
    }
    track.push(randomstring);
    code = ss.getRange(2, 5, lastRow, 1).setValue(track);
    // This is the body of the auto-reply
    message = "Hi <b>" +username+ " !!!</b> <br><br> Your message has been successfully received.<br>";
    GmailApp.sendEmail(usermail, subject, messag, 
                       {bcc: bcc, name: sendername, htmlBody: message});
    } catch (e) {
        Logger.log(e.toString());
    }
}
But I want to generate unique code for every submission. Please update me.
 
     
     
    