如果响应等于值,则值等于“”

时间:2013-12-05 11:46:54

标签: google-apps-script

我正在尝试将此添加到我的脚本中,所以当有响应让我们说“区域T / L”时,区域T / L将等于“名称”(例如杰克说“我现在使用此脚本”工作得很好只是希望能够在发送电子表格之前编辑响应

这是我的

 response = itemResponse.getResponse().toString();  // get the corresponding answer
 if (typeof response === 'undefined') response = '';

完整的脚本

 function onSubmit(e) {
 var myemail = "processauditdatabase@gmail.com"  // please, replace myemail by your email 
  try{
  var formResponse = e.response;//get the form response
  var editResponseUrl = formResponse.getEditResponseUrl(); //get the individual form url just in case the       respondent needs to edit its anwers later
  var itemResponses = formResponse.getItemResponses();// get all item questions and anwers
  var itemResponse
  var title
  var response
  for (var i = 0; i < itemResponses.length; i++) {    // iterate for all form items
    itemResponse = itemResponses[i];
    title = itemResponse.getItem().getTitle().toUpperCase(); // get the question title. In our form can be    EMAIL or NAME
    response =  itemResponse.getResponse().toString();  // get the corresponding answer
    if (typeof response === 'undefined') response = '';
    if(title.indexOf("AUDITOR", 0) != -1){   // if the title is "AUDITOR NAME"
      var auditor = response.toUpperCase();  // get it
    }
    else if (title.indexOf("JCI", 0) != -1){  // if the title is "STATION NAME"
      var work = response.toUpperCase(); // get it
    }
    else if (title.indexOf("RELATED", 0) != -1){  // if the title is "ISSUES FOUND"
      var found = response.toUpperCase(); // get it
    }
    else if (title.indexOf("DEPARTMENT", 0) != -1){  // if the title is "DEPARTMENT RESPONSIBLE"
      var department = response.toUpperCase(); // get it
    }
    else if (title.indexOf("RESULTS", 0) != -1){  // if the title is "NAME"
      var results = response.toUpperCase(); // get it
      }
  }
  var subject = results + ",\n\n"; // body of the message you're assembling
  subject += "Process Confirmation Audit, \n\n"; // body of the message you're assembling
  subject += department + ",\n\n"; // body of the message you're assembling
  var message = auditor + ",\n\n"; // body of the message you're assembling
  message += "Just Completed Station Audit \n\n"; // body of the message you're assembling
  message += work + ",\n\n"; // body of the message you're assembling
  message += "FAILED AUDIT ISSUES FOUND:\n\n"; // body of the message you're assembling
  message += found + ",\n\n"; // body of the message you're assembling
  message += "Please Assign Ownership For This Issue:\n\n"; // body of the message you're assembling
  message += "Click On The Link Below To Review/Assign Ownership Responsibilites:\n\n"; // body of the message you're assembling
  message += editResponseUrl + "\n\n"; // body of the message you're assembling
  MailApp.sendEmail("processauditdatabase@gmail.com", subject, message); // send the message
 }
 catch(e) {             // if something wrong happens 
  MailApp.sendEmail(myemail, "Error in Auto replying to contact form submission.", e.message); // tell me
  }
 }

1 个答案:

答案 0 :(得分:0)

你的逻辑很好,但我们遇到了一些问题。 回答你永远不会在这种情况下被定义。 也许你得到一个“没有定义的东西”的错误。

检查itemResponse和getResponse是否返回定义的值,然后检查响应是否为空,将其与“”进行比较。

你可以这样使用

...
response =  itemResponse.getResponse().toString();  // get the corresponding answer
if (response === 'area1 T/L') response = '';
...