I have a student registration form, there's student id which is a required field. I have a google apps script function which tells if this student is registered for any class or not. Is there a way to auto-fill the field course registered via calling the google apps script function yes or no.
Asked
Active
Viewed 1.1k times
3
-
Yes. You can build a prefilled URL in code. A prefilled URL will fill all or some questions. A Form submitted from a prefilled URL will submit a new response, as opposed to editing an existing response. – Alan Wells Jun 29 '16 at 00:38
-
check this question http://stackoverflow.com/questions/38086855/autofill-a-google-form-fields-based-on-a-spreadsheet – Juan Diego Antezana Jun 29 '16 at 08:11
-
Above link is no longer available. This answer gives URL example: https://stackoverflow.com/questions/20108511/is-it-possible-to-prefill-a-google-form-using-data-from-a-google-spreadsheet – aNewb Apr 05 '21 at 16:43
1 Answers
3
Yes you can create a pre filled response with the forms ID, not that the pre filled fields are showed in the URL
Function formPrefill(formId){
var form = FormApp.openById(formId);
try{
var items = form.getItems();
var formResponse = form.createResponse();
// Prefill SessionId
var formItem = "SOMETHING HERE"
var response = formItem.createResponse(sessionId);
formResponse.withItemResponse(response);
//--------ANOTHER FIELD-------------
formItem = items[4].asMultipleChoiceItem();
response = formItem.createResponse('YOUR FIELD NAME');
formResponse.withItemResponse(response);
}catch(e){catch an error here}
}
check https://developers.google.com/apps-script/reference/forms/form#createresponse

Juan Diego Antezana
- 902
- 4
- 16