Question

I'm trying to create a dynamic form based on a stored form. The code I wrote is not working.

When the users that got the form to fill in, run it, it should first modify all the texts and replace the word kkkk with a keyword determined according to the last submit.

If that cannot be done, then I would like the form when submitted to be modified for the next time it is opened. Is that possible.

I understand that code in onOpen() and onSubmit() do not have permissions to modify the form. So I made my own modifyForm() function, and added a trigger to From-Form On-Submit. Still not working.

The code DID work when I had the trigger set to From-Form On-Open, but only when I closed the form and re-opened it for editing. - That behavior is documented. So, again, I'm looking for a way that each time the form is run, or each time the form is submitted, it is dynamically modified.

function onModify(){
    var form = FormApp.getActiveForm();

    var imgURL = "http://whatever.com/someimg.jpg";
    var img = UrlFetchApp.fetch(imgURL);
    // i first check that there is an image item in the current form and then
    var imgItem = form.getItems(FormApp.ItemType.IMAGE)[0];
    imgItem.setImage(img);

    var keyword = "aaaa"; //getKeyword(); // some text returning function
    var items = form.getItems();
    for (i=0; i<items.length; i++){
       var title = items[i].getTitle();
       title = title.replace("kkkk", keyword); 
       items[i].setTitle(title);
    }

    return form;
}

Thanks for any help you can give!!

Was it helpful?

Solution

Not possible on google forms alone.

So my solution was to create four stored copies of the form replacing "kkkk" keyword in advance, all going to the same spreadsheet but to different sheets, and on a separate website I decide in python which copy of the form to present to the user by redirecting.

I have to store some sort of identification so that the user does not get two types of the form (but that's a separate issue).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top