...
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 | ||
---|---|---|
| ||
On This Page:
|
Rule syntax and best practices to follow are discussed in the Writing Rules to Retrieve and Update Data in a Google Sheet topic.
...
- It’s triggered by clicking on the Connect button.
- We setup headers and a query using your access token and spreadsheet key (the long ID in the URL of the Google Sheet).
- Run the query – perform an http.get() and eval the results.
- Parse the results into an array. The array elements are “hagen=Walter Hagen” etc.
- Set the options to the array.
Tip |
---|
The column name on a Google sheet must match the control name. The matching is case-insensitive and any spaces in the column name are ignored. A control named "FirstName" matches a column header "first name." However, references to Google Sheet columns in your rule must be lower case and cannot contain spaces. The correct reference for this example is "firstname." |
Step 3: Try it yourself
You can try it yourself by clicking this link or clicking on the image.
Populating Checkbox or Radio Options from a Google Sheet
...
- Create a Google Sheet with a column named Colors containing a list of colors.
- Create a Form with a Checkbox/Radio control named Colors.
Use this rule to populate the Checkbox/Radio 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 your Google Sheet and <the name of the worksheet> to reflect the name of the worksheet tab in your Google Sheet.
- The rule executes when the form loads and performs an http.get() then evals the results.
- The results are parsed into an array. The array elements are red=Red, blue=Bue, green=Green and orange=Orange
- The Color Checkbox/Radio control options are set to the array.
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] = x.results[i].colors; } } } Colors.options = opts; //Colors is the name of the Checkbox/Radio control } |