Reputation: 33
I want to create a personalised form using a Google Apps script, but couldn't find the way in the documentation. For example, the for a different user the questions would be:
... and so on
Is this possible with Google Apps Script?
Upvotes: 3
Views: 4605
Reputation: 4053
Now in 2014, yes, you can make a dynamic form:
There are three places where you change the form.
You can create several standard forms in advance and serve out a different form to each different user, or group of users: First make the first form. Then make a script that mails this form to the users you want, then iterate through all the items and replace the text. (See code at bottom of this post)
You can create a standard form, then replace certain text each time before serving the form. This can be done with the onOpen() trigger.
Note: It could be that this does not work as documented. I was not able to use this method, and the onOpen() was working only for opening the document FOR EDITING not for FILLING. I don't want to go into this too deeply, but it seems contrary to the documentation, which states that the OPEN-FOR-EDITING limitation applies only to the installable trigger and not oto the simple trigger.
Not a very good idea.
Here's the code for the first solution (and the third)
function setQuiz(keyword, replacement){
var keyword = ...
var replacement = ...
var form = FormApp.getActiveForm();
var items = form.getItems();
var txt;
for (i=0; i<items.length; i++){
txt = items[i].getTitle();
txt = txt.replace(replacement, keyword);
items[i].setTitle(txt);
txt = "";
txt = items[i].getHelpText();
txt = txt.replace(replacement, keyword);
items[i].setHelpText(txt);
}
return form;
// CREATE A COPY of the form
// and send email with link to the form's COPY in next method, which will be done, only after this method replaced all texts. (see issue with solution 3)
// note you'll have to iterate between the replacement texts each time. So if you start out with tree to mountain, you must remember to change mountain to river...
Upvotes: 1
Reputation: 8650
The short answer is in the comments. A little bit detailed answer is
[email protected] tree [email protected] mountain [email protected] river
Session.getActiveUser().getEmail()
function, find the email in the array.label.setText('Describe a "' + usersWord + '"');
Upvotes: 0