Can I populate TextItem with Google script applications?

I made a form with Google Form Builder, then add a script for it.

I can run Session.getEffectiveUser (). getEmail () to the respondentโ€™s email address. but I canโ€™t fill it in the text box to help them. Can I do this using the Google Script app?

+3
source share
2 answers

I think I found a solution to your problem. But I must admit that this was not obvious. In the documentation for the application scripts, you have everything to create a pre-populated URL .
BUT for this you need to have an ItemResponse element, and I did not find an explanation for creating it. The trick is that if you have an item , you can get an ItemResponse from it if you get it as a specific type of " asTextItem () ".
The best way to understand this is to look at the code below:

function getPreFilledItem(){ var form = FormApp.openById("YOUR_FORM_ID"); var items = form.getItems(); var itemOfInterest; for(var i in items){ if(items[i].getTitle()=="YOUR_QUESTION_TITLE"){ itemOfInterest=items[i]; } } Logger.log( form.createResponse(). withItemResponse(itemOfInterest.asTextItem().createResponse("PREFILLED_TEXT")). toPrefilledUrl() ); } 

Hope this helps you
Harold

+5
source

You cannot dynamically change Google forms by adding a script to the form. See the recent question I asked to better understand.

Basically, you can use the Google Apps script to automatically create forms. You cannot set values โ€‹โ€‹for the elements yet (I hope they add this in the future ...).

You can also see the restrictions for forms by looking at the documentation ( TextItem, for example) .

+2
source

All Articles