0

I created a form collecting requests in a spreadsheet and then upon formsubmission sending out a customized email to the appropriate parties.

There is just 1 small problem. I am not asking for first and last name of the requester, instead i am automatically grabbing the email address. This is simply to minimize the fields user have to complete.

The email address firstname.lastname@company.com naming convention.

function  sendFormByEmail(e) {
  var timestemp = e.values[0];        // 
  var e_email = e.values[1];          // email of requester
  var dept = e.values[2];             // dept
  var type_leave = e.values[3];       // type of leave
  var first_day = e.values[4];        // first day
  var last_day = e.values[5];         // last day 
  var number_days = e.values[6];      // # of days
  var comments = e.values[7];         // comments 

  var formatted_first_day = Utilities.formatDate(new Date(first_day), "GMT-5", "EEEE, MMM dd, YYYY");
  var formatted_last_day = Utilities.formatDate(new Date(last_day), "GMT-5", "EEEE, MMM dd, YYYY");

  var name = e_email;
  var split_name =  name.split("@")[0];
  var first_name = split_name.split(".")[0];
  var last_name = split_name.split(".")[1];

  // var formatted_first_name = first_name.toTitelCase();

I have extracted the first name and last name by using split but my question is, how could i capitalize them so the name becomes from john doe to John Doe.

Many thanks for your help

JC66
  • 45
  • 1
  • 7

1 Answers1

1

I figured it out, so here it is to help others.

var formatted_first_name = first_name.charAt(0).toUpperCase() + first_name.slice(1);
var formatted_last_name = last_name.charAt(0).toUpperCase() + last_name.slice(1);
JC66
  • 45
  • 1
  • 7