Formulas are a great way to move the logic out of your apps and into Cloud Elements. This helps keep your code less complex and more maintainable. This tutorial will be your guide on how to create a formula using events to automate business logic at the API layer in the Cloud Elements platform. To watch an on-demand webinar on how to do so click here.
When you log into Cloud Elements, click the ‘Formulas’ button on the left side of the platform. To create a new Formula, use the ‘Build New Formula Template’ button.
You’ll then have the option to add an Event Trigger. Triggers are the events or conditions you choose to begin the workflow created in a formula. There are four different ways to trigger a workflow:
- An incoming event
- Element Request
- Scheduled job
- Manual start
Creating a Formula with an Event Trigger
For this example, we’ll be listening for the event of a new contact creation in Salesforce. This event will then trigger adding the new contact information it into our Hubspot account, in order to keep those two applications in sync.
Once you open your Formula template you’ll come to this screen:
WATCH THE FULL WEBINAR -
CLOUD ELEMENTS 2.0: HOW TO WRITE FORMULAS
Step 1: Adding a Variable
To create an Event Triggered Formula, click the Event button which will bring you to the edit Event “Trigger” screen. Click the 'add' button to add an Element Instance variable.
There are two kinds of Variables in Formulas. The first one is a value Variable and this is just like your traditional Variable with a key and input, such as a date. The second type of variable is an Element Instance variable, which acts as a container for an Element Instance. In this example use an Element Instance variable as a placeholder to listen for those Events from the origin application.
Step 2: Creating Steps
From here, you can start building out steps. Steps are how to start orchestrating the data between two systems. Adding a step is really straightforward. Click on the blue glowing button to underneath your trigger to add a new step.
Then you can add in a brand new step from one of our available Formula step types or you can add from any existing step types that you’ve created before.
In this demo, we’re going to add an existing step.
Step 3: Editing Steps
If you click on the step and hit this 'edit' button, you can pull up the syntax that you’re using to create that step.
Since this is a filter step, the outcome that you want is a Boolean value. With a filter step, you can use it to do branching logic. When you return a true value, set it up to move to the next step in your Formula and when it returns a false, your Formula will exit gracefully.
Reference our documentation around this just to get a better idea of the dot notation object.
Step 4: Element Request
In the tutorial, we give it the name like 'Retrieve Contact'. The name that you give it isn't too important it's just helpful to give it a name that highlights what it’s doing in referencing the formula.
Step 5: Setting up an Element Instance Variable
Once you set up an Element Request you’ll need to point it to an Element Instance variable. You’ll do the same steps as you did when you were setting up an Event Trigger; hit the 'add' button to see the variables that are available. The goal of this step is based on the Trigger, you get an object type and a reference to an object ID inside of that Trigger. All you need to do is pull down that object that changed in our origin application.
That's done by putting together that API call. In this example, we set up the method as a GET call, as well as the endpoint that you want to be calling in order to pull down that changed object.
The outcome of this is a transformed contact from your origin when it's been created. You now have a payload that you can directly send to the Destination Instance. In the context that we're working with here, when a contact is created in Salesforce, a common contact is pulled down and then pushed to HubSpot.
Step 6: Setting up an Element Instance Variable Again
The next step in this Formula is another Element Request step. This is a similar step as above but this time you’ll be referencing the Destination Instance and referencing the POST method to the same contacts endpoint.
However, in this step, you’ll be using some fields under the 'Show Advanced' tab. In this context, we're taking the ‘Body’ from the previous Retrieve Contact step, which you can see is referenced using dot notation
That's the final step that we need in order to put together this template.
Step 7: Test The Formula Template
The next step is testing the Formula. We’ve added some great test tools that make it easy to test from inside the builder, click “Setup Test”. Including testing on different instances of Elements but also selecting past instances to use specific payloads. After running your formula, you’ll be able to see a breakdown result of each of the steps in the Formula. If one of your steps failed, you can easily start debugging from that step.
See step by step how to test a Formula reference the webinar recording.