Formula Builder II: Using Filter Steps In Your Formula

Vivek Ravishankar

Using Filter Steps When Creating a Formula

Video Transcript:

Hey guys, welcome back to the Formula Builder videos here. I want to show how to tweak our Formula that we made in the first video just a little bit. Let’s say I only want to listen for “contact updated” events. So I don't want the Formula to run for any events that are received from my CRM Element, I want it to run for only certain events. So let me show you how to add a filter step to filter out any data that we are not interested in.

1) So let's do that now. I'm logged into our console. We still have my crm to email Formula we built in the first video so let's click edit on this.


2) Let's click on the steps screen.



3) So here are the current steps we have, we listen for events, we construct our email body from those events, and then we send that email. But let's say we are only interested, like I mentioned, in “updated contact” events. So what I'm going to do is I'm going to create a new step, let's choose the filter step.




4) So for a filter step, as the docs show, you pass a true or false to the done callback, and if it's true it'll call the “on-success” step that's defined in this step, and if it's false it'll call the “on-failure” step, and if there is no “on-failure” it will stop executing. So I'm going to name this step “filter-events” and then I'm going to write some JavaScript to filter my events. So, what I am going to do here is we're going to pass if the event type is updated and the object type is contact, then this will evaluate to “true” and that will pass true to the done callback, otherwise it will return false. So let's save this step, and let's plug this in right after the trigger, because that's the first thing we want to do.




5) If the event isn't for an updated contact, then we don't want to do anything else. So I'm going to change the “on success” here to be “filter-events”, and then I'm going to change the “filter-events” to got to “construct-email-body”. Perfect, and now you can see we've inserted that filter here. So these two steps will only run if it was for a “contact updated” event.




6) So now I'm going to hop over to our Salesforce account and I'm going to actually update a contact to make sure we do get that event. So I'm going to add a phone number to this contact here, and click save here which should send an event to the Cloud Elements platform which should click off our Formula, and that should actually still send me an email because that was a contact updated.




7) So let's go ahead and check my email. Perfect, you'll see that I did get get a “contact with ID ..” was updated, so that happened properly.




8) Now, let's actually create a new account in Salesforce, and let's make sure that I do not get an email there. So add another account “JoshTestAccount”, and click save here. So that saved, and now let's go over to my email and make sure I did not get an email.




9) Perfect, so you'll see in my email here that I have not gotten an email for the new account because we are filtering those events now with that filter step.




10) One other thing I want to show is actually how you can see these executions in our console. So let's go back to the console and on the left side you'll see this “executions” panel.




11) So if I click executions, click “my Formula instance”, here are all the times the Formula has executed so far. So let's click on the last execution, and you can see “filter-events” actually failed because that was not a “contact updated” event.




12) The one right before that we did about 30 second before that, if I click that you can see that all four steps ran successfully because the “filter-events” detected that it was a “contact-updated” event, and therefore they all ran.




13) So here's another helpful screen that can help you debug, you can actually click on these and see the step execution values, and you can kind of use this to debug your Formula executions.


So that's how to add a filter step. Thanks guys!

About the Author

Vivek Ravishankar

Vivek is a Marketing Intern at Cloud Elements.

Previous Video
Formula Builder I: Creating Your First Formula
Formula Builder I: Creating Your First Formula

Introduction to Formula Builder UI and how to go about building your first Formula.

Next Video
Formula Builder III: Using Variables In Your Formula
Formula Builder III: Using Variables In Your Formula

How to Use Variables in Your Formulas