Workato Tip: Simplify recipes with modular recipe functions
Have you ever wished you could reduce your recipe complexity by reusing your common functionality across recipes? You can do exactly that with recipe functions! Recipe functions allow you to enhance consistency and build more efficiently by creating callable recipe functions that can be used in multiple recipes throughout your projects.
Prefer video? Check out this segment of our recent Product Hour:
Benefits of recipe functions: The 3 R’s
Recipe functions allow you to practice the principles of DRY (Don’t Repeat Yourself), by creating reusable functions that can be called from any other recipe. There are three primary benefits to using recipe functions:
- Reusability: Encapsulating common logic in a single function gives you the ability to reuse functionality. This means you only need to build that logic once, instead of building it across many different recipes. This accelerates the time to value for all of your automation builders.
- Readability: Consolidating complex steps into a single recipe function simplifies the main recipe, making it easier to read and understand. This is especially valuable when dealing with lengthy or intricate processes.
- Reliability: Using recipe functions ensures that common operations are performed consistently across your workspace. Whether it’s data cleansing, validation, or error handling, you can standardize how these tasks are executed, reducing variability and potential errors.
When should you use recipe functions
Here are some of the most common areas we see recipe functions being valuable:
- Error handling and notifications: Consistent error handling is crucial. For example, you might need to notify your IT team of errors in a standardized way. Instead of implementing this differently in every recipe, you can create a recipe function for error notifications. This ensures that errors are always handled uniformly.
- Data cleansing, validation, and enrichment: Data cleansing and validation are common tasks that can benefit from recipe functions. You can create functions that validate and clean data, then reuse them wherever needed. For example, you could create a recipe to validate emails and use it across many different recipes handling email data. This ensures that data is held to the same cleanliness standards across your different applications.
- Shared business processes: For shared business processes, recipe functions can standardize operations across different teams or departments. For example, you could have a single recipe function for creating a new contact in Salesforce that is used both by your sales team and your marketing team. This ensures they are taking the same approach to data entry reducing any discrepancies that might otherwise occur.
Real-world example: Creating a standard error notification function
Step 1: Create your function
First things first, create a new recipe and select ‘Build a recipe function’ as your starting point.
Step 2: Define input and output schema
Next, you need to decide what information needs to be provided to your recipe function and what information it will return to the calling recipe. For our error notification function, we will want to provide fields with information that will tell our Business Technology team about the error that occurred. In our case, we won’t return any information to the calling recipe, but you could return a copy of the message sent to the BT team or some other confirmation message.
Step 3: Implement the function logic
Next, you get to actually build the logic for your recipe function! The logic here can be as complex as required. You can even call other recipe functions from inside this one. For our example, we will add a single Slack action to send a properly formatted error notification over to our Business Technology team.
Step 4: Replace existing step(s) with your new recipe function
All that’s left is to go back to your original recipe and add an action to call this recipe function! When you add your action to call your recipe function, you’ll be able to choose whether to do so synchronously or asynchronously. Synchronous calls means the calling recipe will stop and wait for the function to finish before moving on to the next step, while asynchronous calls means the calling recipe will move on to the next step without waiting.
Then just fill out the required mappings from the schema you created, and you’re done!
Bonus points
This recipe function is a big improvement from having to rebuild your error notification step in every new recipe, but there is always room for improvement. Here are some of the ways you could take this to the next level:
- Conditionally change the notified team: In our example all error notifications go to our Business Technology team, but you may want to notify a different team for different projects. You could incorporate this into your recipe function adding conditional logic to send alerts to multiple sources based on what project is throwing an error.
- Add backup notification channels: Sending a Slack notification is a great first step, but what if Slack is down? The recipe function could be enhanced with error handling and additional actions to send notifications to any number of different channels to make the notification process more robust.
Regardless of your particular use case, recipe functions can enhance your recipe readability, ensure consistency, and accelerate time to value for your builders. Try them out and see how you can enhance your workflows and achieve more consistent results across your workspace.