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.

Demo

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).

The Google Sheet with the lookup is here.
The Demo Tree is here.

.

Setup

  1. 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:

  2. Important: The tab name for the lookup table should be the default Sheet1.
  3. Make sure the spreadsheet is publicly accessible. In Sheets, click Share, and make sure “Anyone on the internet with this link can view” appears.

  4. Note the ID of your spreadsheet. When viewing the sheet, the ID is in the URL – like this (bolded):
    https://docs.google.com/spreadsheets/d/1ACNOEksZ6pL0J2UD1BhxM7zPVWWDcd4Svtpb-oPmRVY/edit?usp=sharing
  5. 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:
    https://zingtree.com/apps/webhook/google_sheets_lookup.php?search=#code#&sheet_id=1ACNOEksZ6pL0J2UD1BhxM7zPVWWDcd4Svtpb-oPmRVY

    #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.

  6. 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).

  7. 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.

You can examine this decision tree (or make a copy) here.

Did you find this useful? Let us know!