User enters information on Form A. On form A submission, an on submit trigger runs a sheet side appscript function to look up information (no issues there) and then runs a function to populate a short text type response on Form B. Form A and Form B are hosted on the same Google sites page. Form B does not populate

I have read and experimented with everything I can find on this site. I can get the code to run but I can’t get data to actually populate in form B.

I even tried to build an HMTL form using webapp but ran into same problem I can’t programmatically change response text on the Google sites page.

I’ve tried to reference form B through:

  1. getting the URL from the sheet linked to form B
  2. using the form Id from either the edit or view source URL
  3. Getting form B prefill link and replacing items

I tried to adapt the following answers located at: Answer by Mogsdad

      //Function run by onsubmit trigger
      //form B prefill code

      function prefill(){
  
      //get url using form B sheet  
      var sheet_ID ='sheet B ID'; 
      const ss = SpreadsheetApp.openById(sheet_ID);
      const sheet = ss.getSheetByName('Form Responses 1');
      var formUrl = ss.getFormUrl();  
      console.log(formUrl)
  
      // open form B- get form items - create response array
      var form = FormApp.openByUrl(formUrl);
      var items = form.getItems();
      var formResponse = form.createResponse();

      // Prefill a short text response
      var formItem = items[0].asTextItem();

      var response = formItem.createResponse("my data");
      formResponse.withItemResponse(response);
  
      // submit response ( also tried urlfetch post method)
      formResponse.submit();
      // nothing fills on Form B
     };
0

There are 0 best solutions below