javascript - Google Script maker to format a spreadsheet -


this first time posting bear me if leave crucial details out.

anyway, summarize problem: have been trying script work on google script maker format spreadsheet hooked form, go straight email.

so user form --> spreadsheet --> my email

the questions pretty standard:

  1. what's problem?
  2. where located

however 1 question i'd use "what priority of problem?" high or low. have under multiple choice format simple choice.

psuedocode want:

if (priority = low) put #priority low onto email 

simple enough, can't seem work, here's code:

function sendformbyemail(e)  {         // remember replace xyz own email address     var email = "email";       var subject = "help desk form submitted";        var s = spreadsheetapp.getactivesheet();     var headers = s.getrange(1,1,1,s.getlastcolumn()).getvalues()[0];         var message = "";      var priority = "";      if(message.indexof("what priority of problem? =           low")){         priority += "#priority low";     }     else         priority == "gfhhffhahfh ";      for(var in headers){         message += headers[i] + ' =  \t \t'+ e.namedvalues[headers[i]].tostring() + "\n\n";  }      if (message.indexof("what priority of problem? =           low"))         message += "this test";     else         message += "this not test";      mailapp.sendemail(email, subject, message);  } 

let's @ first instance of if(message.indexof().... it's got problems:

  • a few lines earlier, message set empty string... won't find "priority" string in it.

  • the if statement treating return of indexof() boolean. however, return code .indexof() -1 when item not found, "true-ish". if string found, , located @ start of search subject, return 0, "false-ish". if found @ other location, value `>0', "true-ish".

  • in else, there's typo. comparison == should assignment =, or += if prefer.

  • looking @ surrounding code, piece looks left-over previous version, , can deleted.

now @ second instance.

  • the message should populated. however, comparison still using incorrect boolean interpretation of .indexof().

  • the search string contains batch of spaces... previous code looped through responses used tabs separate "header" "value", search return '-1' (which interpreted true).

there couple of other tidy-up items. need:

function sendformbyemail(e)  {       logger.log(json.stringify(e));   var email = session.geteffectiveuser().getemail();   var subject = "help desk form submitted";     var message = "";     var s = e.range.getsheet(); // sheet received form response   var headers = s.getdatarange().getvalues()[0];       (var question in headers) {     message += headers[question] + ' = \t\t' + e.values[question] + '\n\n';   }    // add text relative priority of reported issue.   if (e.namedvalues["what priority of problem?"].tostring() === "low")     message += "this test";   else     message += "this not test";    logger.log(message);   mailapp.sendemail(email, subject, message);  } 

ps: can see why advisable keep form questions short, "priority", , leave explanatory sentence helper text!


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -