Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Section
Column

Let's take a look at populating a dynamic pick lists (drop downs) using a business rule. It’s a very common scenario and, with frevvo, you can use business rules to dynamically initialize the options (choices) in a pick list from a Google Sheet. We’ll use this sample Google Sheet to discuss. It has a row for each employee: First Name, Last Name, Employee Id.

Column
width240px

On This Page:

Table of Contents


Rule syntax and best practices to follow are discussed in the Writing Rules to Retrieve and Update Data in a Google Sheet topic.

Step 1: Obtain an access token

...

  1. Click the down arrow on the Select Employee dropdown to verify that the employee pick list is initially empty.



  2. Click the Connect button and it will populate from this Google spreadsheet.The pick list will display the actual names (Walter Hagen, Alexa Stirling etc.) whereas the values returned upon selection will be the ids (hagen, stirling etc.) so it’s easy to perform further lookups.

Populating Dropdown Options from a Google Sheet

Here is another example of a simple rule that populates a dropdown control named Colors with color options from a Google Sheet.

  • Create a Google Sheet with a column named Colors containing a list of colors.

     
     Image Added

  • Create a Form with a dropdown control named Colors.

  • Use this rule to populate the dropdown options with the colors Red, Blue, Green and Orange. Note this rule uses http headers to provide authentication information. The Google Sheet is identified by the spreadsheet key and the worksheet name is passed as a query parameter. This is the recommended approach.

  • Replace <Google User ID>  and <Google Account access token> with your information in the user and password  headers. 

  • Change <your spreadsheet key> to the key for you Google Sheet and <the name of the worksheet> to reflect the name of the worksheet tab in your Google Sheet.

Code Block
/*member colors, password, user, results */
var x;
if (form.load) {
var headers = 
{"user":"<Google user Id>","password":"<Google Account access token>"};    
 var readquery = '/google/spreadsheets/query/key/<your spreadsheet key>?wsname=<the name of the worksheet>';
    eval('x=' + http.get(readquery,headers));                                                                                   
  
    var opts = [''];
    if (x.results) {
        for (var i = 0; i < x.results.length; i++) {
            if (x.results[i].colors) {
                opts[i + 1] = x.results[i].colors;
            }
        }
    }
    Colors.options = opts;    //Colors is the name of the dropdown control
}

Image Added