0

here이라는 Google 양식 확인 이메일 트리거를 설정했습니다. 한편, 연결된 답안지는 모든 제출에 대해 별도의 열 (제 경우의 열 B)에서 고유 ID를 계산합니다. 이는 수식을 통해 here입니다.Google 설문지 확인 이메일 (연결된 시트의 정보 포함)

내가 달성하고자하는 것은이 고유 ID를 확인 이메일에 삽입하는 것입니다. 문제는 양식 스크립트에서 적절한 스프레드 시트 필드를 참조하는 방법을 모르겠다는 것입니다.

나는 e.values[1]으로 실험했으나 효과가없는 것처럼 보입니다.

function setup() { 

    /* First, delete all previous triggers */ 
    var triggers = ScriptApp.getProjectTriggers(); 

    for (var i in triggers) { 
    ScriptApp.deleteTrigger(triggers[i]); 
    } 

    /* Then add a trigger to send an email on form submit */ 
    ScriptApp.newTrigger("sendConfirmationEmail") 
    .forForm(FormApp.getActiveForm()) 
    .onFormSubmit() 
    .create(); 
} 

function sendConfirmationEmail(e) { 
    // e is a Form Event object - see https://developers.google.com/apps-script/guides/triggers/events#google_forms_events 

    // Edit this to set the subject line for the sent email 
    var subject = "Data Entry Successful"; 

    // This will show up as the sender's name 
    var sendername = "John Smith"; 

    // This is the body of the registration confirmation message 
    var message = "Thank you for submitting the details of your project!<br><br>"; 
    message += "Your form responses were:<br><br>"; 

    // response is a FormResponse - see https://developers.google.com/apps-script/reference/forms/form-response 
    var response = e.response; 

    var textbody, sendTo, bcc; 

    // Get the script owner's email address, in order to bcc: them 
    bcc = Session.getActiveUser().getEmail(); 

    // Now loop around, getting the item responses and writing them into the email message 
    var itemResponses = response.getItemResponses(); 
    for (var i = 0; i < itemResponses.length; i++) { 
    var itemResponse = itemResponses[i]; 
    message += itemResponse.getItem().getTitle() +": " + itemResponse.getResponse() + "<br>"; 
    // If this field is the email address, then use it to fill in the sendTo variable 
    // Check that your form item is named "Please enter your email address" or edit to match 
    if (itemResponse.getItem().getTitle() == "Please enter your email address") { 
     sendTo = itemResponse.getResponse(); 
    } 
    } 

    message += "<br><a href=\"" + response.getEditResponseUrl() + "\">Please click here</a> if you wish to edit your data or include additional details at a later date.<br>It is essential that you submit any editing through this provided link, since your response data is exclusive only to you. Please do not share your unique edit link with others.<br>If the link doesn't work properly, please copy the following link address manually and then paste it directly into your browser's URL bar:<br>" + response.getEditResponseUrl() + "<br><br><br>Sincerely,<br>John Smith"; 
    message += "<br><br>"; 
    textbody = message.replace("<br>", "\n"); 

    GmailApp.sendEmail(sendTo, subject, textbody, 
         {bcc: bcc, name: sendername, htmlBody: message}); 
} 

그리고이 내 목표를 달성하려고 시도한가있다, 그러나 그것은 작동하지 않습니다 :

function setup() { 

    /* First, delete all previous triggers */ 
    var triggers = ScriptApp.getProjectTriggers(); 

    for (var i in triggers) { 
    ScriptApp.deleteTrigger(triggers[i]); 
    } 

    /* Then add a trigger to send an email on form submit */ 
    ScriptApp.newTrigger("sendConfirmationEmail") 
    .forForm(FormApp.getActiveForm()) 
    .onFormSubmit() 
    .create(); 
} 

function sendConfirmationEmail(e) { 
    // e is a Form Event object - see https://developers.google.com/apps-script/guides/triggers/events#google_forms_events 

    // Edit this to set the subject line for the sent email 
    var subject = "Data Entry Successful"; 

    // This will show up as the sender's name 
    var sendername = "John Smith"; 

    // This is the body of the registration confirmation message 
    var message = "Thank you for submitting the details of your project!<br><br>"; 
    message += "Your form responses were:<br><br>"; 

    // response is a FormResponse - see https://developers.google.com/apps-script/reference/forms/form-response 
    var response = e.response; 

    var textbody, sendTo, bcc; 

    // Get the script owner's email address, in order to bcc: them 
    bcc = Session.getActiveUser().getEmail(); 

    // Get the sheet-generated ID of the submission 
    var activitID = e.values[1]; //ID number from column B 

    // Now loop around, getting the item responses and writing them into the email message 
    var itemResponses = response.getItemResponses(); 
    for (var i = 0; i < itemResponses.length; i++) { 
    var itemResponse = itemResponses[i]; 
    message += itemResponse.getItem().getTitle() +": " + itemResponse.getResponse() + "<br>"; 
    // If this field is the email address, then use it to fill in the sendTo variable 
    // Check that your form item is named "Please enter your email address" or edit to match 
    if (itemResponse.getItem().getTitle() == "Please enter your email address") { 
     sendTo = itemResponse.getResponse(); 
    } 
    } 

    message += "The ID of the submitted activity is: " + activitID + "<br><br><a href=\"" + response.getEditResponseUrl() + "\">Please click here</a> if you wish to edit your data or include additional details at a later date.<br>It is essential that you submit any editing through this provided link, since your response data is exclusive only to you. Please do not share your unique edit link with others.<br>If the link doesn't work properly, please copy the following link address manually and then paste it directly into your browser's URL bar:<br>" + response.getEditResponseUrl() + "<br><br><br>Sincerely,<br>John Smith"; 
    message += "<br><br>"; 
    textbody = message.replace("<br>", "\n"); 

    GmailApp.sendEmail(sendTo, subject, textbody, 
         {bcc: bcc, name: sendername, htmlBody: message}); 
} 
다음

는 시트에 대한 참조 (흠이 하나의 기능) whithout 스크립트입니다

두 개의 activitID 부분을 코드에 추가하고 다른 부분을받는 사람에게 보낼 메시지에 추가했습니다.

내가 어떻게이 작업을 할 수 있는지에 대한 아이디어가 있습니까?

답변

0

고유 ID를 가정하면 응답과 같은 행에, 당신은 대체를 시도 할 수 있습니다 :

// Get the sheet-generated ID of the submission 
    var activitID = e.values[1]; //ID number from column B 

로 :

// Get the sheet-generated ID of the submission 
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses 1'); //rename to your sheet name 
var row = e.range.getRow(); 
var activitID = sheet.getRange("B" + row).getValue(); //ID number from column B 

편집 주석 사항에 따라

를 :

원본 코드의 일부입니다. 하지만 코드 편집기에서 리소스> 현재 프로젝트 트리거로 이동하여 거기에서 수행합니다.

function setup() { 
    /* First, delete all previous triggers */ 
    var triggers = ScriptApp.getProjectTriggers(); 

    for (var i in triggers) { 
    ScriptApp.deleteTrigger(triggers[i]); 
    } 

    /* Then add a trigger to send an email on form submit */ 
    var sheet = SpreadsheetApp.getActive(); 
ScriptApp.newTrigger("sendConfirmationEmail") 
    .forSpreadsheet(sheet) 
    .onFormSubmit() 
    .create(); 
} 

그냥이 부분을 사용

function sendConfirmationEmail(e) { 

    var form = FormApp.openById("1lBkYf3eRnDzeXJnvawkxvWb5WGYgK14HzApwDmDyWSY"); 
    var formResponses = form.getResponses(); 
    //var response = form.getResponses(); 

    // e is a Form Event object - see https://developers.google.com/apps-script/guides/triggers/events#google_forms_events 

    // Edit this to set the subject line for the sent email 
    var subject = "Data Entry Successful"; 

    // This will show up as the sender's name 
    var sendername = "John Smith"; 

    // This is the body of the registration confirmation message 
    var message = "Thank you for submitting the details of your project!<br><br>"; 
    message += "Your form responses were:<br><br>"; 

    // response is a FormResponse - see https://developers.google.com/apps-script/reference/forms/form-response 

    var textbody, sendTo, bcc; 

    // Get the script owner's email address, in order to bcc: them 
    bcc = Session.getActiveUser().getEmail(); 

    // Get the sheet-generated ID of the submission 
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses 1'); //rename to your sheet name 
    var row = e.range.getRow(); 
    var activitID = sheet.getRange("B" + row).getValue(); //ID number from column B 

    // Now loop around, getting the item responses and writing them into the email message 

    var r = formResponses.length-1; 
    var editURL = formResponses[r].getEditResponseUrl(); 

    var formResponse = formResponses[r]; 
    var itemResponses = formResponse.getItemResponses(); 
    for (var j = 0; j < itemResponses.length; j++) { 
    var itemResponse = itemResponses[j]; 
    message += itemResponse.getItem().getTitle() +": " + itemResponse.getResponse() + "<br>"; 
    // If this field is the email address, then use it to fill in the sendTo variable 
    // Check that your form item is named "Please enter your email address" or edit to match 

    if (itemResponse.getItem().getTitle() == "Enter in Your email to receive a confirmation.") { 
     sendTo = itemResponse.getResponse(); 
    } 
    } 

    message += "The ID of the submitted activity is: " + activitID + "<br><br><a href=\"" + editURL + "\">Please click here </a> if you wish to edit your data or include additional details at a later date.<br>It is essential that you submit any editing through this provided link, since your response data is exclusive only to you. Please do not share your unique edit link with others.<br>If the link doesn't work properly, please copy the following link address manually and then paste it directly into your browser's URL bar:<br>" + editURL + "<br><br><br>Sincerely,<br>John Smith"; 
    message += "<br><br>"; 
    textbody = message.replace("<br>", "\n"); 

    GmailApp.sendEmail(sendTo, subject, textbody, 
        {bcc: bcc, name: sendername, htmlBody: message}); 
} 
+0

는 답변을 utphx을 주셔서 감사합니다. 슬프게도, 당신의 대답은 스크립트가 작동하지 않습니다. 응답 시트 제목을 변경했지만 이메일을 전송하지 않았습니다. 이전의 시도와 마찬가지로이 기능이 중단 된 것 같습니다. – mozzribo

+0

귀하의 가정을 명확히하기 위해 : 예, 고유 ID는 응답과 동일한 행에 있습니다. – mozzribo

+0

오류에 대한 실행 기록을 확인할 수 있습니까? 또는 Logger.log (activitID)를 사용하여 ID가 ​​있는지 확인하십시오. – utphx

관련 문제