Ryan
Ryan

Reputation: 1050

Google Apps Script Prefilled Form - Cannot Edit Form

I have a Google Form I send out to all the customers who have a booking with us in the upcoming weekend.

Up until now I have successfully been able to pre fill the form for each customer depending on their booking information, but this does not work for me since the customer could edit this information - and break my system.

Rather, I want to fill a Page Break items' help text as their booking ID, so the user cannot edit it and I am guaranteed to find it in the system.

When looping through each upcoming booking, and generating a pre-filled URL, I am now setting the Page Break help text to their booking ID, but it is setting all of the pre-filled forms with the same booking ID. (As as I can tell, the first one works successfully, it is each form after that which is incorrect.)

Any help would be greatly appreciated! Current code is below:

function getPreFilledFormURL(bookingSheetID) {

  // open the form and create a response and get the items
  var formId = "My Form ID (ommitted)";
  var form = FormApp.openById(formId);
  var formResponse = form.createResponse();
  var formItems = form.getItems();
  
  // set booking ID in sectio description
  var sectionHeader = formItems[0].asPageBreakItem();
  sectionHeader.setHelpText(bookingSheetID);
  
  return formResponse.toPrefilledUrl();
}

Upvotes: 0

Views: 687

Answers (1)

Ryan
Ryan

Reputation: 1050

So what I have realised is that I am editing the actual form itself, which edits the form for everyone viewing it. This means that even someone with a pre-filled form link will still see changes to the form - it isn't unique to their URL.

It looks like my only option is to put the bookingID as a question - and warn the user to not edit the answer...

Not the best solution, but it seems to be my only option.

Upvotes: 1

Related Questions