Formun tamamına verilen yanıt. Form
üç şekilde kullanılabilir: yanıtlayanın gönderdiği yanıtlara erişmek için (get
), forma programatik olarak yanıt göndermek için (with
ve submit()
) ve sağlanan yanıtları kullanarak alanları önceden dolduran bir form URL'si oluşturmak için. Form
'ler Form
üzerinden oluşturulabilir veya bunlara erişilebilir.
// Open a form by ID and log the responses to each question. const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const formResponses = form.getResponses(); for (let i = 0; i < formResponses.length; i++) { const formResponse = formResponses[i]; const itemResponses = formResponse.getItemResponses(); for (let j = 0; j < itemResponses.length; j++) { const itemResponse = itemResponses[j]; Logger.log( 'Response #%s to the question "%s" was "%s"', (i + 1).toString(), itemResponse.getItem().getTitle(), itemResponse.getResponse(), ); } }
Yöntemler
Yöntem | Dönüş türü | Kısa açıklama |
---|---|---|
get | String | Daha önce gönderilmiş bir yanıtı düzenlemek için kullanılabilecek bir URL oluşturur. |
get | Item | Form yanıtında bulunan tüm öğe yanıtlarını, öğelerin formda göründüğü sırayla alır. |
get | Item | Belirli bir öğe için form yanıtında yer alan öğe yanıtını alır. |
get | String | Form yanıtının kimliğini alır. |
get | Item | Form yanıtında bulunan tüm öğe yanıtlarını, öğelerin formda göründüğü sırayla alır. |
get | String | Form.setCollectEmail(collect) ayarı etkinse yanıt gönderen kişinin e-posta adresini alır. |
get | Item | Belirli bir öğe için bu form yanıtında yer alan öğe yanıtını alır. |
get | Date | Form yanıtı gönderiminin zaman damgasını alır. |
submit() | Form | Yanıtı gönderir. |
to | String | Bu form yanıtındaki yanıtlara göre, yanıtların önceden doldurulduğu form için bir URL oluşturur. |
with | Form | Belirtilen öğe yanıtının notlarını bir form yanıtına ekler. |
with | Form | Belirtilen öğe yanıtını bir form yanıtına ekler. |
Ayrıntılı belgeler
get Edit Response Url()
Daha önce gönderilmiş bir yanıtı düzenlemek için kullanılabilecek bir URL oluşturur. Form.setAllowResponseEdits(enabled)
ayarı devre dışı bırakılırsa bağlantı, form yanıtlarının düzenlenmesinin devre dışı bırakıldığını açıklayan bir sayfaya yönlendirir. Bağlantıyı ziyaret eden herkes yanıtı düzenleyebilir. Ancak
ayarı etkinse formun erişilebildiği bir hesap gerekir. Form.setRequireLogin(requireLogin)Form.setCollectEmail(collect)
ayarı etkinleştirilirse form, yanıtı düzenleyen kullanıcının e-posta adresini orijinal yanıtlayanın e-posta adresi yerine kaydeder.
Komut dosyasının oluşturduğu ancak henüz gönderilmeyen bir form yanıtı için bu yöntem null
değerini döndürür.
// 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);
Return
String
: Gönderilen bir yanıtı değiştirmek için kullanılan URL.
Yetkilendirme
Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri veya daha fazlasıyla yetkilendirme gerektirir:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
get Gradable Item Responses()
Form yanıtında bulunan tüm öğe yanıtlarını, öğelerin formda göründüğü sırayla alır. Bu yöntem get
ile benzer şekilde çalışır ancak eksik bir yanıtın puanlanmasına izin vermek için gerçek bir yanıt olmasa bile karşılık gelen Item
puanlanabiliyorsa (yani puan değeri varsa) yine bir Item
döndürür. Ancak Item
derecelendirilemiyorsa bu yöntem, söz konusu öğeyi döndürülen diziden çıkarır.
// 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()}`); } }
Return
Item
: Yanıtlayanın puan alabileceği, formdaki her soru öğesine verilen yanıtlar dizisi.
Yetkilendirme
Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri veya daha fazlasıyla yetkilendirme gerektirir:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
get Gradable Response For Item(item)
Belirli bir öğe için form yanıtında yer alan öğe yanıtını alır. Bu yöntem get
işlevine benzer şekilde çalışır ancak eksik bir yanıtın notlandırılmasına olanak tanımak için, gerçek bir yanıt olmasa bile karşılık gelen Item
notlandırılabilirse (yani puan değeri varsa) Item
değerini döndürmeye devam eder. Ancak Item
derecelendirilemiyorsa bu yöntem null
değerini döndürür.
// 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()}`, ); }
Parametreler
Ad | Tür | Açıklama |
---|---|---|
item | Item |
Return
Item
: Belirli bir öğenin yanıtı veya yanıt yoksa ve öğe notlandırılmamışsa null
.
get Id()
Form yanıtının kimliğini alır. Bu yöntem, form yanıtı gönderilmediyse null
değerini döndürür.
// 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()}`); }
Return
String
: Form yanıtının kimliği veya form yanıtı gönderilmediyse null
.
Yetkilendirme
Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri veya daha fazlasıyla yetkilendirme gerektirir:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
get Item Responses()
Form yanıtında bulunan tüm öğe yanıtlarını, öğelerin formda göründüğü sırayla alır. Form yanıtı, belirli bir Text
,
Date
, Time
veya Paragraph
için yanıt içermiyorsa Item
öğesi için döndürülen yanıtta boş bir dize bulunur. Form yanıtında başka bir öğe türü için yanıt atlanırsa bu yöntem, söz konusu öğeyi döndürülen diziden çıkarır.
// 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()}'`); } }
Return
Item
: Yanıtlayanın yanıt verdiği formdaki her soru öğesine verilen yanıtların dizisi.
Yetkilendirme
Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri veya daha fazlasıyla yetkilendirme gerektirir:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
get Respondent Email()
Form.setCollectEmail(collect)
ayarı etkinse yanıt gönderen kişinin e-posta adresini alır.
Komut dosyasının oluşturduğu ancak henüz gönderilmeyen bir form yanıtı için bu yöntem null
değerini döndürür.
// 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()}`); }
Return
String
: Bu yanıtı gönderen kişinin e-posta adresi (varsa) veya null
(komut dosyası bu yanıtı oluşturduysa ancak henüz göndermediyse).
Yetkilendirme
Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri veya daha fazlasıyla yetkilendirme gerektirir:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
get Response For Item(item)
Belirli bir öğe için bu form yanıtında yer alan öğe yanıtını alır.
// 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()); }
Parametreler
Ad | Tür | Açıklama |
---|---|---|
item | Item |
Return
Item
: Belirli bir öğeyle ilgili yanıt veya yanıt yoksa null
.
get Timestamp()
Form yanıtı gönderiminin zaman damgasını alır.
Komut dosyasının oluşturduğu ancak henüz gönderilmeyen bir form yanıtı için bu yöntem null
değerini döndürür.
// 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()}`); }
Return
Date
: Bu yanıtın gönderildiği zaman damgası veya komut dosyası bu yanıtı oluşturduysa ancak henüz göndermediyse null
.
Yetkilendirme
Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri veya daha fazlasıyla yetkilendirme gerektirir:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
submit()
Yanıtı gönderir. Yanıt daha önce gönderilmişse komut dosyası oluşturma istisnası oluşturur.
// 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();
Return
Form
: Forma yeni kaydedilen yanıt.
Yetkilendirme
Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri veya daha fazlasıyla yetkilendirme gerektirir:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
to Prefilled Url()
Bu form yanıtındaki yanıtlara göre, yanıtların önceden doldurulduğu form için bir URL oluşturur.
// 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);
Return
String
: Önceden doldurulmuş yanıtlar içeren bir formun URL'si.
Yetkilendirme
Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri veya daha fazlasıyla yetkilendirme gerektirir:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
with Item Grade(gradedResponse)
Belirtilen öğe yanıtının notlarını bir form yanıtına ekler. Bu yöntem yalnızca daha önce gönderilmiş form yanıtları için geçerlidir ve yalnızca gönderildikten sonra depolanan notları etkiler. Bu yöntem yalnızca öğe yanıtının notlarını günceller. Yanıt zaten gönderildiği için gerçek yanıtı etkilemez. Bu yöntem aynı öğe için birden çok kez çağrılırsa yalnızca son not korunur. ItemResponse not içermiyorsa bu yöntem, öğenin notlarını kaldırır.
// Programmatically award partial credit for a given response const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const formResponses = form.getResponses(); const formItems = form.getItems(); for (const formResponse of formResponses) { for (const item of formItems) { const points = item.asMultipleChoiceItem().getPoints(); const itemResponse = formResponse.getGradableResponseForItem(item); Logger.log('Award half credit for answers containing the word "Kennedy"'); const answer = itemResponse.getResponse(); if (answer?.includes('Kennedy')) { itemResponse.setScore(points / 2); formResponse.withItemGrade(itemResponse); } } } form.submitGrades(formResponses);
Parametreler
Ad | Tür | Açıklama |
---|---|---|
graded | Item |
Return
Form
: Zincirleme için Form
Yetkilendirme
Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri veya daha fazlasıyla yetkilendirme gerektirir:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
with Item Response(response)
Belirtilen öğe yanıtını bir form yanıtına ekler. Bu yöntem yalnızca komut dosyasının oluşturduğu ancak henüz gönderilmeyen form yanıtları için geçerlidir. Kayıtlı yanıtları etkileyemez. Bu yöntem aynı öğe için birden çok kez çağrılırsa yalnızca son öğe yanıtı korunur.
// 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();
Parametreler
Ad | Tür | Açıklama |
---|---|---|
response | Item |
Return
Form
: Zincirleme için bu Form
.
Yetkilendirme
Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri veya daha fazlasıyla yetkilendirme gerektirir:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms