0
votes

What I want to achieve?

I want to track the review status of a google document with a google form with dropdown options as "To do, In progress, Done". I have google form items as "URL of document, Status". I have created a google form template that I'll be using to create forms for various users. I want to be able to create a copy of the template form, and set predefined value of "URL" from google apps script, so that the users just have to select the status of the document.

What I tried?

I came across createResponse() method from this answer, but this requires .submit() to be used to save the response and the answer is recorded in sheets. I don't want to submit the form from the script itself. Here is the code:

function form()
{
  var form  = FormApp.create("Test");
  form.addTextItem().setTitle("URL");
  form.addTextItem().setTitle("Status");

  var items = form.getItems();
  var url = items[0].asTextItem();
  var fr = url.createResponse('my predefined url');

  var FormResponse = form.createResponse();
  FormResponse.withItemResponse(fr);
  FormResponse.submit();
  Logger.log(form.getPublishedUrl());
}

Final query:

How do I get the published URL of the form with the pre-filled answer to the URL item from the apps script? Is it possible?

1
I'm sorry to say this but currently it is not possible.Jeff Rush
Actually I was able to achieve it using .toPrefilledUrl() method. I have mentioned it in the answer below.Tech Girl

1 Answers

1
votes

Turns out there is a method .toPrefilledUrl() which resturns the published url of form with prefilled values. Here is an example:

  var form  = FormApp.openByUrl("url");
  var items = form.getItems();
  var url = items[0].asTextItem();
  var d= "some.url"
  var fr = url.createResponse(d);

  var FormResponse = form.createResponse();
  var urlPub = FormResponse.withItemResponse(fr).toPrefilledUrl();
  Logger.log(urlPub);