Find us at our new Help Center where we've combined our documentation and knowledgebase articles in one easy-to-search location.
We aren't updating the Developer Portal anymore, except for the Element Docs — all updates happen in the Help Center. We're retiring the Developer Portal as you know it in:
The examples in this section show a selection of common use cases for formulas. Each example includes a table that identifies the types of triggers, steps, and variables used in the formula. The table also identifies any prerequisites required, like an element with events. Lastly, each example includes a downloadable JSON file that you can use to create your own version of the example template with the POST /formulas
endpoint.
This example listens for an event on a CRM element and then sends an email with that event information using a messaging element. This example was tested with the Salesforce Sales Cloud and SendGrid elements.
Trigger | Step Types | Variable Types | Prerequisites | Template JSON |
---|---|---|---|---|
Event | Element Instance |
|
Formula JSON |
To create a formula that listens for an event and emails a message:
Because the trigger is a change to a CRM element, add an element instance variable that refers to a CRM element.
crmElement
.Select the variable that you just created (crmElement
), and then click Save on the Edit event: "trigger" page.
Your formula visualization should look like the following example:
Add another element instance variable for the messaging element.
messagingElement
.In the formula visualization, click to add a step.
Create a JS Script step that constructs a message when the trigger happens.
constructBody
.Enter a script that constructs a message, such as the example below.
done( {
"subject": "CRM Event Occurred",
"to": "receipient@cloud-elements.com",
"from": "sender@cloud-elements.com",
"message": `${trigger.event.objectType} with ID ${trigger.event.objectId} was ${trigger.event.eventType}`
});
Click Save.
Create an Element API Request step to send the message that you created in the previous step. Click the constructBody step, and then click Add OnSuccess.
sendEmail
./messages
.${steps.constructBody}
.Your formula should look like the visualization below. It should include a trigger and two steps: the first constructs an email and the second sends a message.
This example listens for a new contact on one element instance, and then adds the new contact to another element instance. The trigger for the formula is an Event. When a new contact is created at an element instance that has events set up, the trigger receives a payload with the raw contact information. Because this raw data cannot be used to create the same contact at a different element instance, the formula uses the objectID
from the trigger to get the transformed contact instead. The formula then posts the transformed contact to the target element instance.
For this example to work, you must define a common resource to transform the data received from Salesforce.
This example was tested with the Salesforce Sales Cloud and HubSpot CRM elements.
Trigger | Step Types | Variable Types | Prerequisites | Template JSON |
---|---|---|---|---|
Event | Element Instance |
|
Formula JSON |
To create a formula that adds new contacts created in one system to another:
Because the trigger originates from an element instance configured to listen for events, add an element instance variable.
originInstance
.Select the variable that you just created (originInstance
), and then click Save.
Your formula visualization should look like the following example:
Add another Element Instance variable to represent the system to update after you create a contact at the originInstance
.
destinationInstance
.In the formula visualization, click to add a step.
Create a JS Filter step that checks to be sure the event is a created contact, and not an updated or deleted contact.
isCreateContact
. let theEvent = trigger.event.eventType;
let theObject = trigger.event.objectType;
done((theEvent === 'CREATED') && (theObject === 'Contact' || theObject === 'contacts'));
Create an Element API Request step to retrieve the transformed version of the newly created object based on the objectId
in the trigger. Click the isCreateContact step, and then click Add OnSuccess.
objectId
from the trigger to retrieve the transformed object. If you just retrieved the information about the object from the event payload in the trigger, it would not be transformed and could not sync with another element. retrieveOriginalContact
.In API, retrieve the transformed newly created contact by entering the endpoint of the common resource and specifying the objectId
from the trigger. For this tutorial, the common resource is called myContacts
.
/MyContacts/${trigger.event.objectId}
Click Save.
Create an Element API Request step to add the contact to another element instance. Click the retrieveContact step, and then click Add OnSuccess.
createContact
.In API, enter the API to the common resource. For this tutorial, the common resource is called myContacts
.
/MyContacts
Click Show Advanced.
Scroll to Body and enter the reference to the step with the transformed contact data. In this case, type ${steps.retrieveOriginalContact.response.body}
. This inserts the body from the retrieveOriginalContact
step—the JSON describing the transformed contact—in the POST request to the destinationInstance
.
Click Save.
Your formula is finished and should look like the visualization below. It should include a trigger and three steps: the first checks that an event is a created contact, the second gets the transformed contact data, and the third syncs the contact.
Bulk data transfer is a common use case. For example, your first sync between CRM systems or maybe you add many accounts or contacts each day and want a single job to run to sync between systems. This example demonstrates how to use two formulas to complete a bulk transfer.
Trigger | Step Types | Variable Types | Prerequisites | Template JSON |
---|---|---|---|---|
|
|
To create a formula that makes a bulk query and then triggers the second formula that will download and then upload the bulk files:
Add a cron string to identify when the sync occurs.
This example fires every Monday through Friday at 1:00 a.m..
0 0 1 ? * MON,TUE,WED,THU,FRI *
Add three variables for the 1) The resource that you want to sync (like account
or contact
), 2) The element instance that includes the resources that you want to sync and, 3) The formula instance id associated with the second formula (Formula 2) in this process.
resourceName
.stepTwoId
.originInstance
.In the formula visualization, click to add a step.
Create a JS Script step that builds the metadata for the bulk query, including the CEQL query that requests a specific resource and the callback URL that will be the formula execution endpoint that executes Formula 2.
buildMetaData
. done ({
"query":{
"q":"select * from " + config.resourceName
},
"headers":{
"Elements-Async-Callback-Url":"/formulas/instances/" + config.stepTwoId + "/executions"
}
});
Create an Element API Request step to make a bulk download query, referencing the query and callback URL created in buildMetaData. Click the buildMetaData step, and the click Add OnSuccess.
bulkQuery
.In API, enter the endpoint to make a bulk query.
/bulk/query
Click Show Advanced.
In Headers, enter the reference to the headers that you built in the script in the buildMetaData
step. In this case, type ${steps.buildMetaData.headers}
.
In Query, enter the reference to the query that you built in the script in the buildMetaData
step. In this case, type ${steps.buildMetaData.query}
.
Click Save.
The first formula should look like the visualization below. It should include a trigger and two steps: the first builds the metadata for a bulk query, and the second makes the bulk query, which includes a callback to the formula execution endpoint of the next formula.
To create a formula that receives the notification that the job completes, downloads the file from the original element, and posts to the destination:
Build a formula template and select Manual as the trigger, and then click Save.
Add two element instance variables to represent the element that you are downloading from and the element that you are uploading to, and a variable to represent the resource that you are syncing.
resourceName
.originInstance
and destinationInstance
.In the formula visualization, click to add a step.
Create a JS Filter step that makes sure that the bulk query is completed.
isSuccessful
. let status = trigger.args.status;
if (status && status === "COMPLETED") {
done(true);
} else {
done(false);
}
Create a JS Script step that defines an identifier field, which is the unique key for an upsert operation. It also specifies the content type as csv. Click the isSuccessful step, and then click Add OnSuccess .
buildMetaData
. const metaData = {
"identifierFieldName":"email"
}
const downloadHeaders = {
"Accept":"text/csv"
};
done({
"metaData": metaData,
"downloadHeaders": downloadHeaders
});
Create an Element Stream step to move the files downloaded from the origin instance to the destination instance. Click the buildMetaData step, and then click Add OnSuccess .
bulkStream
.GET
./bulk/${trigger.args.id}/${config.resourceName}
. ${trigger.args.id}
gets the id from the payload sent to the trigger by Formula 1. ${config.resourceName}
refers to the resourceName variable that identifies the resource that you want to sync.POST
./bulk/${config.resourceName}
. ${trigger.args.id}
.buildMetaData
step. In this case, type ${steps.buildMetaData.downloadHeaders}
.buildMetaData
step. In this case, type ${steps.buildMetaData.metaData}
.The second formula should look like the visualization below.