MoniteScript
Learn and explore all the possibilities of MoniteScript.
Overview
MoniteScript is our unique declarative programming language based on JSON syntax that allows the creation of complex business logic scenarios related to business logic objects.
Through MoniteScript, it is possible to implement customized scenarios, such as:
- Set a specific approval policy for all payables with more than 300 EUR worth to be approved by a specific entity user.
- Set a specific approval policy for all payables between 1000 and 5000 GBP worth to be approved by any user with a specific role.
Currently, MoniteScript supports only the payable
object. More objects will be added to MoniteScript in the near future.
The sample script below defines an approval policy in which all the payables over 500 worth submitted for approval must be approved by at least two users from a given list:
A MoniteScript script consists of two parts:
trigger
: The conditions for the script execution.script
: The main logical statement executed.
Trigger
The trigger
defines the conditions that cause the script
to be executed by combining expressions with the parameters event_name
and invoice
(both mandatory). The only value allowed for the event_name
parameter is submitted_for_approval
. For the invoice
parameter you can use the attributes of the invoice object such as invoice.amount
, invoice.project_id
, and invoice.tags.name
.
According to the sample trigger
below, all payables submitted for approval above 500 worth will be affected by the script
:
Check out some examples of triggers designed to assign automated approval policies for payables.
Script
The script
is the main logical statement to be executed.
Below is an example of a script
function. This example requires approval from two users from a given list:
MoniteScript language
The elements that compose the MoniteScript language are described below:
Connectors
A connector represents a business logic object as a class in the MoniteScript language. The connector has a group of methods to deal with a certain piece of functionality in MoniteScript.
The call
clause is followed by the connector method that is going to be called. Optionally accepts params
whose values are instances of a raw expression. Every parameter from that expression is going to be passed as an argument to the chosen connector method:
The connectors can also use the any
and all
expressions:
any
all
The supported connectors are Payables
and ApprovalRequests
.
Payables
The Payables
connector has methods that allow you to modify the status of the payable. The params
must be declared in raw expression.
The available methods and parameters of the Payables
connector are:
mark_as_paid(payable_id: uuid, comment: str)
approve(payable_id: uuid)
reject(payable_id: uuid)
add_tags(payable_id: uuid, tags: list[str])
Examples:
mark_as_paid
approve
reject
add_tags
ApprovalRequests
The ApprovalRequests
connector is used to require approvals from users or roles. It has the following methods:
request_approval_by_users(object_id: uuid, user_ids: list[uuid], required_approval_count: int)
request_approval_by_roles(object_id: uuid, role_ids: list[uuid], required_approval_count: int)
Examples:
request_approval_by_users
request_approval_by_roles
If statement
The if statement consists of three clauses: if
, then
, and else
. An if
clause can contain any expression that evaluates to a boolean value, while then
and else
clauses contain a JSON array of other statements. The else
clause is optional.
Expressions
The expressions used in MoniteScript are:
Primitives
Primitives expressions include all JSON primitive types:
- null
- boolean
- number
- string
Array
Evaluates to a JSON array of values, each one of which is also an expression. It is used inside any and all expressions.
Any
Returns true
if at least one of the values in its array expression is true. For example, {"any": [true, false, false]}
evaluates to true
.
All
Returns true
only if all of the values in its array expression are true. For example, {"all": [true, false, false]}
evaluates to false
.
Not
Evaluates to a boolean that is the complement of its inner expression.
Binary operation
Compares two operands and evaluates the result of the operation. The following operators are supported:
==
!=
=
<
or>
<=
or>=
Name
Retrieves the values of the variable Event
, which has all the information about the event that triggered the execution of a MoniteScript script.
Name expression supports the basic operations of access on the object: square bracket indexing (object_list[0]
) and dot access (object.attribute
).
Connector name
Evaluates to specific methods from the connector classes. It uses the same syntax as the name expression with the only difference being that it evaluates to a non-JSON object.
As a result, connector name expression can only be used within call expressions.
Raw
Evaluates to a JSON object. It is only necessary because many other expressions are also JSON objects. The raw expression exists to distinguish expressions from regular JSON objects.
Evaluated string
The evaluated string expression can evaluate to other expressions in the MoniteScript language. It allows writing simple scripts without delving into the complexities of binary operations and calls.
They are regular JSON strings wrapped in { }
, to distinguish them from non-evaluated strings.
The different types of evaluated string are:
Primitive string
Evaluates to a simple string.
Evaluated string:
Evaluates to:
Name expression string
Evaluates to a name expression.
Evaluated string:
Evaluates to:
Binary expression string
A one-line syntax that evaluates to a binary operation expression.
Binary expression string:
Evaluates to false
, which is the result of:
However, evaluated strings are recursive, so the following is supported:
Evaluated string:
Evaluates to:
Call string
A one-line syntax that evaluates to a call expression.
Evaluated string:
Evaluates to:
Also, this evaluated string:
Evaluates to:
Chain logic
Chain logic allows you to perform a series of sequential actions on a script, where each action is dependent on the previous one, without needing to write separate lines of code for each action. There are three types of chain logic:
Straight chain
On a straight chain, the first action must be executed before the script continues to the next. In the example below, the first approval must be performed before the second one, so the payable approval can be concluded:
“And” logic
A chain with an “And” condition refers to a situation where multiple conditions or actions are combined together using the all
operator, and all of those conditions must be true or actions must be successfully executed for the overall chain to be considered successful.
In the example below, all approval requests are sent and their approval is required to conclude the payable approval:
“Or” logic
A chain with an “Or” condition refers to a situation where multiple conditions or actions are combined together using the any
operator, and at least one of those conditions must be true or actions must be successfully executed for the overall chain to be considered successful. Once one of the conditions returns true, the next ones will be canceled.
In the example below, only one type of approval is required to conclude the payable approval: