We get asked a lot about how to easily incorporate a lookup table in decision tree logic. For example, you may have a list of part numbers, and want to show the name of the part as a part of your tree presentation. This can be easily done with a simple Google Sheets webhook integration that we provide.
To show how this works, we’ve created a simple demo that returns the name of a country given its two-letter abbreviation code. (Try US or CN as an example).
- Create your spreadsheet in Google Sheets. The first column is what you will search on, and the second column is the result. The variable name for the result is the header of the second column. Ours looks like this:
- Important: The tab name for the lookup table should be the default Sheet1.
- Make sure the spreadsheet is publicly accessible. In Sheets, click Share, and make sure “Anyone on the internet with this link can view” appears.
- Note the ID of your spreadsheet. When viewing the sheet, the ID is in the URL – like this (bolded):
- In Zingtree add a new webhook. From the top menu, click Account, My Apps, Webhooks, and create a webhook like so:
Here’s what the Webhook URL looks like in our demo:
#code# is a placeholder for the variable we use to do the lookup.
The sheet_id parameter is the one you noted in step 3.
- Now create the first node of your tree. Add a data entry field variable named code. The lookup will return a variable named country (from the top row of our spreadsheet).
- Add the second node of the tree. Under Apps/Webhooks, call the webhook you just set up. This will set a variable named country. In the content area, enter #country# to show the name of the country.