In this Core Skills video episode I'm going to explain how Composer's automation engine can be used to automate manual processes and create workflows. The automation engine can be a very powerful part of apps built with Composer.
By creating smart rules that trigger when important things happen in your app or in other services, you can create powerful, automated workflows. You can automate things like setting reminders, sending push notifications, scheduling appointments or even triggering events in external services or Internet-connected devices.
In this episode, we’ll be enhancing an app that tracks mileage for company cars. In our scenario, our accounting company would like get email reports every time someone puts miles on one of the company vehicles. So, we’re going to setup a rule that automatically sends an email every time an employee reports a work-related trip.
The first thing I’ll want to do to is to head to the automation menu item, and I'll add my first rule. All automated actions in Composer happen via rules, each of which is in charge of doing one Action in response to some kind of Trigger.
I start by choosing the Trigger event that causes the rule to fire. From the dropdown, I can choose different kinds of events: most of them involve interactions with the data in my application, like when a data record is viewed, or when new data is created. I’m going to choose the trigger, “when a data record is created” because I want my rule to fire when somebody creates a new mileage report.
Next, I need to choose which data resource the automation engine should monitor for the new data records created. I want to monitor for new mileage reports, so I choose that resource.
Next, let’s take a look at actions. An action is what happens in the application when this particular rule is triggered. There are many options here, and our list is always expanding. But this time, I’ll choose to send an email.
That brings us to trigger settings. Trigger settings are conditions that we choose to be met before the automation continues. An example of this could be that I only want trips longer than 1000 km to be reported to our accounting company. But you don’t have to set a condition and in our example, I’m going to skip it.
That brings us to the email itself. For the from address, I’ll want to add ‘firstname.lastname@example.org’, but it can be anything. And for the recipient email address input my own email address to keep it simple. And I'll hit Add. For the subject, I’ll put ‘Mileage report from’, and then by tapping the @ symbol, I’ll invoke the variable list, and add the variable for the Driver, which is the Driver’s name.
Variables are bits of data you can use in the triggered action. They are determined by the trigger: in this case, all the data fields of then newly created resource are available as variables: things like Driver and Mileage. Variables are powerful because you can use them to write dynamic content for notifications, determine which user to send a push notification to, and much more.
So finally, for the content, we’ll want to add the information that our accounting company is looking for from the milage reports.
Now I’ll save the rule so we can go and check out how it works. Let’s head over to the web app. I’ll quickly create a new milage report.... And voilà, as you can see, the rule has triggered, and the report for my accounting company has automatically shown up in my inbox.
And that about sums it up. Now we’ve now got a rule successfully firing every time a Mileage Report is submitted. Again, rules are really powerful, and there are a lot possibilities to automate things real people would normally have to do manually every day. I suggest you give a thought to see what you can come up with that you might want to automate in your project or business.
If you need a hand or aren’t sure if something is possible, drop us a line at email@example.com.