양식 전체에 대한 응답입니다. FormResponse
은 응답자가 제출한 답변에 액세스하고 (getItemResponses()
참고), 프로그래매틱 방식으로 양식에 응답을 제출 (withItemResponse(response)
및 submit()
참고)하고, 제공된 답변을 사용하여 필드를 미리 채우는 양식의 URL을 생성하는 세 가지 방식으로 사용할 수 있습니다. FormResponse
는 Form
에서 만들거나 액세스할 수 있습니다.
// Open a form by ID and log the responses to each question. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var formResponses = form.getResponses(); for (var i = 0; i < formResponses.length; i++) { var formResponse = formResponses[i]; var itemResponses = formResponse.getItemResponses(); for (var j = 0; j < itemResponses.length; j++) { var itemResponse = itemResponses[j]; Logger.log('Response #%s to the question "%s" was "%s"', (i + 1).toString(), itemResponse.getItem().getTitle(), itemResponse.getResponse()); } }
방법
메서드 | 반환 유형 | 간략한 설명 |
---|---|---|
getEditResponseUrl() | String | 이미 제출된 응답을 수정하는 데 사용할 수 있는 URL을 생성합니다. |
getGradableItemResponses() | ItemResponse[] | 양식 응답에 포함된 모든 항목 응답을 양식에 표시되는 순서와 동일하게 표시합니다. |
getGradableResponseForItem(item) | ItemResponse | 지정된 항목의 양식 응답에 포함된 항목 응답을 가져옵니다. |
getId() | String | 양식 응답의 ID를 가져옵니다. |
getItemResponses() | ItemResponse[] | 양식 응답에 포함된 모든 항목 응답을 양식에 표시되는 순서와 동일하게 표시합니다. |
getRespondentEmail() | String | Form.setCollectEmail(collect) 설정이 사용 설정된 경우 응답을 제출한 사람의 이메일 주소를 가져옵니다. |
getResponseForItem(item) | ItemResponse | 지정된 항목의 양식 응답에 포함된 항목 응답을 가져옵니다. |
getTimestamp() | Date | 양식 응답 제출의 타임스탬프를 가져옵니다. |
submit() | FormResponse | 응답을 제출합니다. |
toPrefilledUrl() | String | 이 양식 응답의 답변을 기반으로 답변이 미리 채워진 양식의 URL을 생성합니다. |
withItemGrade(gradedResponse) | FormResponse | 양식 응답에 지정된 항목 응답의 성적을 추가합니다. |
withItemResponse(response) | FormResponse | 양식 응답에 지정된 항목 응답을 추가합니다. |
자세한 문서
getEditResponseUrl()
이미 제출된 응답을 수정하는 데 사용할 수 있는 URL을 생성합니다. Form.setAllowResponseEdits(enabled)
설정이 사용 중지되면 양식 응답 수정 기능이 사용 중지되었음을 설명하는 페이지로 연결됩니다. Form.setRequireLogin(requireLogin)
설정이 사용 설정되어 있으면 링크를 방문하는 사람은 누구나 응답을 수정할 수 있지만 양식에 액세스할 수 있는 계정이 필요합니다. Form.setCollectEmail(collect)
설정을 사용 설정하면 양식에 원래 응답자의 이메일 주소 대신 응답을 수정한 사용자의 이메일 주소가 기록됩니다.
스크립트가 생성했지만 아직 제출하지 않은 양식 응답의 경우 이 메서드는 null
를 반환합니다.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets the first form response. const formResponse = form.getResponses()[0]; // Gets the edit URL for the first form response and logs it to the console. const editUrl = formResponse.getEditResponseUrl(); console.log(editUrl);
리턴
String
- 제출된 응답을 변경할 URL입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getGradableItemResponses()
양식 응답에 포함된 모든 항목 응답을 양식에 표시되는 순서와 동일하게 표시합니다. 이 메서드는 getItemResponses()
과 유사하게 작동하지만, 누락된 응답을 채점할 수 있도록 실제 응답이 없더라도 해당하는 Item
를 채점할 수 있는 경우 (즉, 점수 값) ItemResponse
을 반환합니다. 그러나 Item
를 평가할 수 없는 경우 이 메서드는 반환된 배열에서 해당 항목을 제외합니다.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets an array of the form's responses. const formResponses = form.getResponses(); // Gets the item responses contained in each form response. for (const formResponse of formResponses){ const gradableItemsResponses = formResponse.getGradableItemResponses(); // Logs the title and score for each item response to the console. for (const gradableItemsResponse of gradableItemsResponses) { console.log(`${gradableItemsResponse.getItem().getTitle()} score ${gradableItemsResponse.getScore()}`); } }
리턴
ItemResponse[]
— 응답자가 점수를 받을 수 있는 양식 내의 모든 질문 항목에 대한 응답의 배열입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getGradableResponseForItem(item)
지정된 항목의 양식 응답에 포함된 항목 응답을 가져옵니다. 이 메서드는 getResponseForItem(item)
과 유사하지만, 누락된 응답을 채점할 수 있도록 실제 응답이 없더라도 해당하는 Item
를 채점할 수 있는 경우 (즉, 점수 값) ItemResponse
을 반환합니다. 그러나 Item
를 평가할 수 없는 경우 이 메서드는 null
를 반환합니다.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets an array of the form's responses. const formResponses = form.getResponses(); // Gets the item responses contained in a form response. for (const formResponse of formResponses) { const formItemResponses = formResponse.getGradableItemResponses(); // Logs the title and score for responses to the first item of the form. const itemResponse = formResponse.getGradableResponseForItem(formItemResponses[0].getItem()); console.log(`${itemResponse.getItem().getTitle()} score ${itemResponse.getScore()}`); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
item | Item |
리턴
ItemResponse
: 지정된 항목의 응답이며, 항목이 없는 경우 null
입니다.
getId()
양식 응답의 ID를 가져옵니다. 양식 응답이 제출되지 않았으면 이 메서드는 null
를 반환합니다.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets an array of the form's responses. const formResponses = form.getResponses(); // Loops through the form responses and logs the ID for each form response to the console. for (const formResponse of formResponses) { console.log(`Response ID: ${formResponse.getId()}`); }
리턴
String
: 양식 응답의 ID 또는 양식 응답이 제출되지 않은 경우 null
입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getItemResponses()
양식 응답에 포함된 모든 항목 응답을 양식에 표시되는 순서와 동일하게 표시합니다. 지정된 TextItem
, DateItem
, TimeItem
또는 ParagraphTextItem
에 관한 응답이 양식 응답에 포함되어 있지 않으면 해당 항목에 대해 반환된 ItemResponse
에는 빈 문자열이 응답으로 포함됩니다. 양식 응답에서 다른 항목 유형에 대한 응답이 생략되면 이 메서드는 반환된 배열에서 해당 항목을 제외합니다.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets the responses to the form. const formResponses = form.getResponses(); // Iterates over the responses. for (const formResponse of formResponses) { // Gets the item responses from each form response. const itemResponses = formResponse.getItemResponses(); // Iterates over the item responses. for (const itemResponse of itemResponses) { // Logs the items' questions and responses to the console. console.log(`Response to the question '${itemResponse.getItem().getTitle()}' was '${itemResponse.getResponse()}'`); } }
리턴
ItemResponse[]
— 응답자가 응답을 제공한 양식 내의 모든 질문 항목에 대한 응답의 배열입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getRespondentEmail()
Form.setCollectEmail(collect)
설정이 사용 설정된 경우 응답을 제출한 사람의 이메일 주소를 가져옵니다.
스크립트가 생성했지만 아직 제출하지 않은 양식 응답의 경우 이 메서드는 null
를 반환합니다.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets an array of the form's responses. const formResponses = form.getResponses(); // Loops through the responses and logs each respondent's email to the console. // To collect respondent emails, ensure that Form.setCollectEmail(collect) is set to true. for (const formResponse of formResponses) { console.log(`Respondent Email: ${formResponse.getRespondentEmail()}`); }
리턴
String
- 응답을 제출한 사람의 이메일 주소입니다(있는 경우). 또는 스크립트가 응답을 작성했지만 아직 제출하지 않은 경우 null
.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getResponseForItem(item)
지정된 항목의 양식 응답에 포함된 항목 응답을 가져옵니다.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets the first item on the form. const item = form.getItems()[0]; // Gets an array of the form's responses. const formResponses = form.getResponses(); // Loops through the responses and logs each response to the first item to the console. for (const formResponse of formResponses) { const itemResponse = formResponse.getResponseForItem(item); console.log(itemResponse.getResponse()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
item | Item |
리턴
ItemResponse
- 지정된 항목의 응답 또는 null
(없는 경우)
getTimestamp()
양식 응답 제출의 타임스탬프를 가져옵니다.
스크립트가 생성했지만 아직 제출하지 않은 양식 응답의 경우 이 메서드는 null
를 반환합니다.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets an array of the form's responses. const formResponses = form.getResponses(); // Loops through the responses and logs the timestamp of each response to the console. for (const formResponse of formResponses) { console.log(`Timestamp: ${formResponse.getTimestamp()}`); }
리턴
Date
- 응답이 제출된 타임스탬프 또는 스크립트가 응답을 작성했지만 아직 제출하지 않은 경우 null
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
submit()
응답을 제출합니다. 응답이 이미 제출된 경우 스크립트 예외가 발생합니다.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Creates an empty response for the form. const formResponse = form.createResponse(); // Submits an empty response. formResponse.submit();
리턴
FormResponse
: 양식의 응답 저장소에 저장된 새로 생성된 응답입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
toPrefilledUrl()
이 양식 응답의 답변을 기반으로 답변이 미리 채워진 양식의 URL을 생성합니다.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets the first form response. const formResponse = form.getResponses()[0]; // Generates and logs the URL of a pre-filled form response based on the answers // of the first form response. const prefilledUrl = formResponse.toPrefilledUrl(); console.log(prefilledUrl);
리턴
String
- 답변이 미리 채워진 양식의 URL입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
withItemGrade(gradedResponse)
양식 응답에 지정된 항목 응답의 성적을 추가합니다. 이 방법은 이미 제출된 양식 응답에만 적용되며 저장된 성적이 제출된 후에만 영향을 미칩니다. 이 메서드는 항목 응답의 성적만 업데이트하며 응답이 이미 제출되었으므로 실제 응답에 영향을 미치지 않습니다. 동일한 항목에 대해 이 메서드를 여러 번 호출하면 마지막 성적만 유지됩니다. ItemResponse에 성적이 포함되어 있지 않으면 이 메서드는 항목의 성적을 삭제합니다.
// Programmatically award partial credit for a given response var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var formResponses = form.getResponses(); var formItems = form.getItems(); for (var i = 0; i < formResponses.length; i++) { var formResponse = formResponses[i]; for (var j = 0; j < formItems.length; j++) { var item = formItems[j]; var points = item.asMultipleChoiceItem().getPoints(); var itemResponse = formResponse.getGradableResponseForItem(item); Logger.log('Award half credit for answers containing the word "Kennedy"'); var answer = itemResponse.getResponse(); if (answer != null && answer.includes('Kennedy')) { itemResponse.setScore(points / 2); formResponse.withItemGrade(itemResponse); } } } form.submitGrades(formResponses);
매개변수
이름 | 유형 | 설명 |
---|---|---|
gradedResponse | ItemResponse |
리턴
FormResponse
— 체이닝용 FormResponse
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
withItemResponse(response)
양식 응답에 지정된 항목 응답을 추가합니다. 이 방법은 스크립트가 만들었지만 아직 제출하지 않은 양식 응답에만 적용됩니다. 저장된 응답에 영향을 주지 않습니다. 동일한 항목에 대해 이 메서드가 여러 번 호출되면 마지막 항목 응답만 유지됩니다.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Creates a response for the form. const formResponse = form.createResponse(); // Appends a checkbox item to the form. const item = form.addCheckboxItem(); // Sets the title of the item to 'Which items are ice cream flavors?' item.setTitle('Which items are ice cream flavors?'); // Sets choices for the item. item.setChoices([ item.createChoice('Vanilla'), item.createChoice('Strawberry'), item.createChoice('Brick') ]); // Creates a response for the item. const response = item.createResponse(['Vanilla', 'Strawberry']); // Adds the item response to the form response. formResponse.withItemResponse(response); // Submits the form response. formResponse.submit();
매개변수
이름 | 유형 | 설명 |
---|---|---|
response | ItemResponse |
리턴
FormResponse
: 체이닝용 FormResponse
입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms