Open Navigation

Polling for Updates

On This Page

When the Tray.io connector for a service you are using has no built-in trigger, and the service itself has no Webhook to subscribe to, you can use a technique we call 'polling' to manually check for updates with the Scheduled Trigger.

This can be used to check for service updates (new records created, new contacts added etc.) e.g. every day, every 30 mins etc.

This is effectively building your very own trigger mechanism in that you can specify the exact conditions that will trigger the rest of the Workflow.

You might also use polling if the service does have a webhook but the data provided in the Webhook payload is not satisfactory.

Simple Polling Example

In this example, we will set up a very simple polling operation which checks if any new lines have been added to a Google Sheet. It makes use of the Google Sheets connector, the Data Storage connector and the Boolean Condition connector.

When creating this workflow remember that each step which uses the Data Storage connector can access a particular variable(s) which may have been set by a previous Data Connector step, i.e. all steps write to and read from a common data store.

The test workflow to set up here is:

poll-test-workflow-3

Note that the Data Storage connectors in this workflow use the 'Workflow' Scope which means that they can store and recall data for all the times this workflow is run (i.e. the variables do not get reset when a run of the workflow is complete).

The idea behind this workflow is:

  • A Google Sheets connector is added which counts the number of rows in a particular sheet
  • Data Storage connectors are used to store and fetch the number of rows. Note that it is the last Data Storage connector which sets the row count value, and the first which fetches it to check if the number of rows has changed since the last workflow run.

Each time the workflow is run:

  1. The Google Sheets connector will count the number of rows in the sheet
  2. The first Data Storage connector will fetch the count from the last run of the workflow
  3. The boolean connector will then check if the number of rows in the sheet is now greater than the number from the last run
  4. If so, then a simple Slack message is sent (in a live situation the more normal outcome would be to use a loop connector to go through the new rows one by one and process them accordingly)
  5. The last Data Storage connector will set the count from Google Sheets so that it can be retrieved in the next run

1 - Set up the Scheduled trigger

Set the Operation for your trigger to Interval and to run every 10 minutes:

scheduled-trigger

2 - Setup the Google Sheets connector

Authenticate with your Google account, choose the Count Total active rows operation and select the correct spreadsheet and worksheet:

g-sheets-count-rows

3 - Add the first Data Storage connector

Set the Operation to Get Value, the Scope to Workflow and the key to row_count

data-storage-1

Note that you can set the Default Value to be the number of rows that currently exist in your spreadsheet, before you start adding any more. This will only apply to the first run of the workflow and means you won't get an error because of a null value.

An alternative method for this would be to set the Default Value to be null and place another Boolean Condition above the first one to check that row_count is not equal to null, to allow for the first run of the workflow.

4 - Set the Boolean Condition

Set the Operation as Boolean Condition, the first value as $.steps.sheets-1.rows to grab the count from Google Sheets, the Comparison Type as Greater than and the second value as $.steps.storage-1.value:

boolean

5 - Add the Slack messages to the 'True' and 'False' paths

Authenticate with your Slack account for both Slack steps, set the Operation as Send Message and choose a channel and short message to indicate that a new row has been added for the 'True' path and that no rows have been added to the 'False' path:

slack-message

6 - Add the second Data Storage connector

Set the Operation to Set Value, the Scope to Workflow and the key to row_count. Then, in Value, grab the count from Google Sheets with $.steps.sheets-1.rows so that it is available for the next run:

data-storage-2

Test the workflow

Once finished, click on 'Enable' to enable the workflow and begin the scheduled checking.

Now go to your actual spreadsheet in your Google Sheets account and add a new row(s).

The next time your workflow is triggered by the schedule, if your workflow is setup correctly, the appropriate Slack message should be triggered and you can click on 'Debug' to check the output logs for each stage of the process.

Was this article helpful?
Yes
No
On This Page