frevvo forms can be initialized with data from a Google Sheet by retrieving the data from the spreadsheet using a business rule.
The example discussed below uses a form that has a dropdown control to select a customer from a list. Once selected, a business rule queries a Google Sheet and retrieves the full address details for the selected customer. City, State and Zip Code controls are also populated with the customer information.
On This Page:
Example 1 - Populate form fields with data from a Google Sheet
Step 1: Obtain an access token for your Google Account
If you do not have an access token for the Google Account where you are going to create your spreadsheet, perform this one-time step.
Follow these steps to obtain your Google Account token. Login to your Google Account Go to: Cloud customers: https://app.frevvo.com/google/consent Click Allow if you see a screen like the one below (Google often updates their UI so this may differ from what you see). Copy the access token. Save it to a safe location, you will use it when configuring your forms/flows.
Login to your Google Account
Cloud customers: https://app.frevvo.com/google/consent
Click Allow if you see a screen like the one below (Google often updates their UI so this may differ from what you see).
Copy the access token. Save it to a safe location, you will use it when configuring your forms/flows.
Step 2 - Create your form
Create a simple example contact form with a few fields. Note the Select Customer control is a dropdown. If you need help creating a form, check out the Quick Demo and Form Designer tutorial videos on our website.
Step 3: Create your Google Sheet
Create a Google Sheet containing the customer address details. Make sure the column header names match the Name property of each control.
|Control Name||Column Header|
Copy the Spreadsheet key to use in the Business Rule
It is best practice to use the spreadsheet key in your business rule to specify the Google sheet. This method is recommended because each spreadsheet has it's own unique key. Using the key instead of the spreadsheet/worksheet name avoids issues that may occur if you have more than one spreadsheet with the same name.
The Google connector supports the use of the key as a path parameter:
- key - the GUID of your Google sheet. Use the key to specify your Google sheet instead of the sheet name (ssname) in your rule.
- To find the Google sheet key,
- Open your Google sheet.
- The key is the long string of characters between the d/ and the /edit in the URL in the address bar.
Step 4: Add the Business Rule
This business rule calls the Google Connector to retrieve the address details from a worksheet named Sheet1 in the Google Sheet associated with the Google Sheet key provided.
Let's take a look at the components of this rule:
- The Google user id and access token for the password are supplied via user and password headers. Note the line beginning with var headers =. If you want to try this example with your own Google sheet, change <Google user id> to your Google account user name and <Google Account access token> to the access token for your account.
- The path parameter, /key, is used to provide the spreadsheet key to identify the spreadsheet.
- The following URL query parameters are used:
- wsname - the rule queries the worksheet (tab) of the Google Connector Address sheet named Sheet1. To connect to your Google sheet, change Sheet1 to reflect the name of the worksheet (tab) in your Google Sheet.
- query=<query string> - This is where you specify which rows to match based on the data in your spreadsheet. The query parameter selects row(s) from the spreadsheet which match values in specific columns. In this example the spreadsheet has a column named 'customer name'. The query parameter retrieves the spreadsheet row where customer name equals the name we select in our form's dropdown control name 'Customer'.
- The http.get returns all the values from the matched row(s) to a variable named "x.results". The rule checks for null which means that no row matched the selected customer.
A few important notes:
- The Google spreadsheet column name is 'customer name'. When you pass this to the query, remove spaces as you see above query=customername. Any references to Google Sheet columns in your rule MUST be lower case and all have all spaces removed .
- If you have spaces in your worksheet or Google Sheet name, do not remove them.
- Notice the double quote characters in the query string added around Customer.value. This is important in cases where your data contains spaces, you need to surround them with double quotes.
- You will always get back an array even for 1 result.
- If there are no results, the returned JSON Object x.results will be null
Example 2 - Read from a Google Sheet using OR condition
The query string supports 'and' and 'or' logic. This query will retrieve all rows where the customer lives either in MA or CT. The rule concatenates all the addresses into a text area control named FullAddress when the form loads.
If you want to try this example with your own Google sheet, remember to change the <Google user id> and the <Google Account access token> to reflect your Google account information. Change <your spreadsheet key> to the key for your Google sheet and <your worksheet name> to the name of the tab in your Google sheet.
If your Google Sheet has this data, then your form will look like the image to the right when the form loads and the rule runs.
Google Address Spreadsheet
Form showing only customer addresses from CT or MA
Example 3 - Generating Sequential Numbers from a Google Sheet
The Google Spreadsheet connector can also be used to generate unique sequential numbers. This technique should not be used if you have multiple people using the form at the same time as it's possible that two people simultaneously opening the same form could get the same sequential number.
In this example we have a checkbook form where we want to initialize a field named CheckNum with the next sequential check book number when the form loads. Here is our Google spreadsheet:
Here is the rule that reads the next sequential number from the spreadsheet and updates plus 1. Note this rule uses http headers to provide authentication information, access the Google sheet using the key and passes the worksheet name 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.
- Replace <your spreadsheet key> with the key for your spreadsheet in the readquery and update statements.
- Replace <the name of the worksheet tab in your spreadsheet> with the name of the worksheet (tab) in your Google sheet in the readquery and update statements.
The rule reads the number in the nextid column of the spreadsheet and populates the Checknum field in the form when the form loads. It then adds 1 and updates the nextid column in the spreadsheet. The Checknum field for the next user to load the form is populated with the incremented value.