Automation
Automation can make your Corteza Low Code application more efficient. With the Automation tool, you can create business logic that evaluates records automatically when they are created, updated, or deleted, or you can execute a rule manually. Automation consists of automation scripts and automation triggers.
Automation script
Automation scripts are written in JavaScript, one of the most used programming languages in the world, enabling you to write simple code that can evaluate, calculate, and transform data (such as numbers, strings, or dates).
Corteza provides some extra functions that help you to access, create, save, or delete records, find users, send notifications via email, use Corteza Messaging, and more.
These functions can be accessed via <ServiceName>.<functionName>
from inside automation scripts.
-
Compose.<functionName>
:Provides helper functions to work with Corteza Low Code, such as accessing, creating and deleting records.
-
ComposeUI.<functionName>
:Provides helper functions to work with user interface for Corteza Low Code, such as opening record pages and showing notifications.
-
Messaging.<functionName>
: Provides helper functions to work with Corteza Messaging, such as finding channels, creating channels and creating messages. -
System.<functionName>
:Provides helper functions to work with Corteza core system, such as finding and creating users and managing role membership.
Scripts that interact with the user interface (page redirects, success/error messages, …) must be ran inside the client’s browser. You can find this setting under automation script’s Settings tab - Run in browser. |
To make automation scripts as flexible as possible, we provide settings for extra configuration. These settings can be found under automation’s script’s Settings tab.
-
Enabled:
If this automation script should be executed.
-
Critical script:
Critical scripts must be executed entirely and without any errors. If an error occurs, it’s execution is canceled and all upcoming automation scripts are ignored.
-
Run this script asynchronously:
Asynchronous scripts are ran in the background and their results are ignored.
-
Run in browser:
Executes this script inside the client’s browser (user-agent). This should only be used for scripts that require user interaction, since this form of execution is not reliable.
-
Script execution timeout:
Specifies the duration in milliseconds, an automation script can execute for before aborting it’s execution.
-
Security:
Specifies what user will be used when the script is executed; defaults to current user
Security setting comes in handy when we want to execute some operations that not all users have access to; creating/updating records, creating users and their roles, … |
Automation trigger
Automation triggers connect automation scripts with resources, allowing the script to run when a specified event happens. We currently support record triggers and scheduled triggers.
Record triggers
Record triggers can be created on any module that is available for this namespace. You can find record triggers under automation script’s Record triggers tab.
-
Before create:
Before a record is created; you can use this trigger to do some validation, generate values, …
-
After create:
After a record is created; you can use this trigger to send notifications, update related records, …
-
Before update:
Before a record is updated; you can use this trigger to do some validation, generate values, …
-
After update:
After a record is updated; you can use this trigger to send notifications, update related records, …
-
Before delete:
Before a record is deleted; you can use this trigger to do some validation, remove related records, …
-
After delete:
After a record is deleted; you can use this trigger to remove related records, notify users, …
-
Manual:
Trigger requires user interaction (a button press) in order to execute; you can use this trigger to convert a lead to a client, remove stale leads, …
When using before update/create automation triggers with an intent to change values for the record that triggered script execution; you don’t need to explicitly save the record; this is done automatically when the script finishes it’s execution. |
When using before update/create automation triggers with an intent of data validation, you can cancel execution by either throwing an |
Scheduled triggers
Scheduled triggers are executed at a specified time or in an interval. They are mainly used for periodic tasks, such as batch record updates, aggregation, updating records based on an external source, … You can find scheduled triggers under automation script’s Scheduled tab.
To use scheduled triggers, you must provide a user that is used for script execution as scripts will be executed on their own. This option is available under automation script’s Settings tab - Security. Make sure, that this user’s permissions allow all required operations that the automation script performs. |
Corteza CRM has an extensive set of automation scripts that can be used as examples. Some of them are:
-
Account: Create new case
-
Account: Create new opportunity
-
Case: Insert case number
-
Contract: Send contract to custom email
-
Lead: Convert a lead into an account and opportunity
-
Opportunity: Apply price book
-
Opportunity: Generate new quote
-
Quote: Submit quote for approval
Automation script development
For easier development, we recommend using our corteza-corredor-sdk repository as a starting point. It provides standardjs code linting (eslint), unit testing (mochajs + chaijs) and mocking (sinon) out of the box. You are also free to use the already provided code editor available under automation script’s Code tab.
A complete manual on how to use the automation module, together with code examples, is in development.