title: Retrieve Data from Google sheet in Google Form Field based on Google Form Drop down selected value
body: <p>I've two columns in my google sheet Institute PID &amp; Institute Name , Now I am creating google form which has two filed Choose PID ( Drop Down) and Institute Name, I used google script to populate all PID in google form drop-down list from Google Sheet now I want like if user select PID from the drop-down so respected institute Name will fetch from google sheet and show inside the google form field.</p>
  <p>I am Sharing code of getting PID from google sheets in Google Form Drop-Down List</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//Spreadsheet ID (Get it in URL)
  var ssID="1O4wHSFYRkjnuf7AX4A7SnJPjijpvuY8oRYeeE";
  //Google Form ID (Get it in URL)
  var formID="1E-ELIgOtzVmB6PO8WbNI0NOsV-r3lORZtnlFQOSg";
  
  // "Institutes" is a name of of sheet
  var wsData= SpreadsheetApp.openById(ssID).getSheetByName("Institutes");
  var form = FormApp.openById(formID);
  
  function main(){
  
    var labels=wsData.getRange(1, 1,1,wsData.getLastColumn()).getValues()[0];
    labels.forEach(function(label,i){
     var options=wsData.getRange(2,i+1,wsData.
       getLastRow()-1,1).getValues().map(function(o){ return o[0] }).
     filter(function(o){
      return o !== "" });
      
      updateDropdownUsingTitle(label,options)
      
    });
  
  }
  
  function updateDropdownUsingTitle(title,values) {
    
    var items= form.getItems();
    var titles=items.map(function(item){
     return item.getTitle();
    });
    
    var pos=titles.indexOf(title);
    var item=items[pos];
    var itemID=item.getId();
    
  
    
    updateDropdown(itemID,values);
  // Logger.log(titles.indexOf(title));
    
  }
  
  function updateDropdown(id,values) {
    
    var item = form.getItemById(id);
    item.asListItem().setChoiceValues(values);
  
  }</code></pre>
  </div>
  </div>
  </p>
  <p><a href="https://i.stack.imgur.com/1hayU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1hayU.png" alt="enter image description here" /></a></p>