Skip to main content

DSL Reference

Complete reference for the DSL (Domain Specific Language) for business rules in Fyso.

General Structure

{
"type": "compute | validate | action",
"triggers": ["campo1", "campo2"],
"triggerType": "field_change | before_save | after_save | on_load",
"compute": { ... },
"validate": [ ... ],
"transform": { ... },
"actions": [ ... ]
}

Compute

Calculates values automatically. Supports several formats:

Simple Formula (shorthand)

{
"compute": {
"total": "cantidad * precio"
}
}

The shorthand is internally normalized to:

{
"compute": {
"total": { "type": "formula", "expression": "cantidad * precio" }
}
}

Explicit Formula

{
"compute": {
"iva": { "type": "formula", "expression": "subtotal * 0.21" },
"total": { "type": "formula", "expression": "subtotal + iva" }
}
}

Conditional

Calculates a value based on conditions:

{
"compute": {
"descuento": {
"type": "conditional",
"conditions": [
{ "when": "cantidad >= 100", "then": "0.15" },
{ "when": "cantidad >= 50", "then": "0.10" },
{ "when": "cantidad >= 10", "then": "0.05" }
],
"default": "0"
}
}
}

Lookup

Looks up a value in another entity:

{
"compute": {
"precio_unitario": {
"type": "lookup",
"entity": "productos",
"matchField": "id",
"matchValue": "producto_id",
"resultField": "precio"
}
}
}
PropertyTypeDescription
entitystringEntity to search in
matchFieldstringField in the target entity to match against
matchValuestringField in the current record containing the value to search for
resultFieldstringField in the target entity whose value to return

Aggregate

Aggregates values from multiple records of another entity:

{
"compute": {
"total_lineas": {
"type": "aggregate",
"entity": "lineas_factura",
"aggregateOp": "sum",
"aggregateField": "subtotal",
"filter": { "factura_id": "id" }
},
"cantidad_items": {
"type": "aggregate",
"entity": "lineas_factura",
"aggregateOp": "count",
"filter": { "factura_id": "id" }
}
}
}
PropertyTypeDescription
entitystringEntity to aggregate
aggregateOpstringOperation: "sum" or "count"
aggregateFieldstringField to sum (required for sum)
filterobjectFilter: { target_field: "current_field" }

Validate

Array of validation rules:

{
"validate": [
{
"id": "precio_positivo",
"condition": "precio > 0",
"message": "El precio debe ser mayor a cero",
"severity": "error",
"field": "precio"
}
]
}
PropertyTypeRequiredDescription
idstringYesUnique identifier for the validation
conditionstringYesBoolean expression that must be true
messagestringYesError message if the condition is false
severitystringYes"error" (blocks save), "warning", "info"
fieldstringNoField to associate the error with in the UI

Transform

Transforms field values:

{
"transform": {
"nombre": { "type": "uppercase" },
"email": { "type": "lowercase" },
"descripcion": { "type": "trim" },
"precio": { "type": "round", "decimals": 2 }
}
}
TypeDescription
uppercaseConverts to uppercase
lowercaseConverts to lowercase
trimRemoves leading and trailing whitespace
roundRounds to N decimal places

Actions

Side effects that execute after saving:

{
"actions": [
{
"type": "update_related",
"entity": "pedidos",
"recordId": "pedido_id",
"data": {
"total": {
"type": "aggregate",
"entity": "lineas",
"aggregateOp": "sum",
"aggregateField": "subtotal",
"filter": { "pedido_id": "pedido_id" }
}
}
}
]
}

Allowed Operators

CategoryOperators
Arithmetic+, -, *, /
Comparison>, <, >=, <=, ==, !=
Logicaland, or

Allowed Functions

FunctionDescriptionExample
round(x, n)Rounds to n decimal placesround(total, 2)
coalesce(a, b)First non-null valuecoalesce(descuento, 0)
abs(x)Absolute valueabs(diferencia)
min(a, b)Minimummin(stock, pedido)
max(a, b)Maximummax(precio, precio_minimo)
floor(x)Round downfloor(cantidad)
ceil(x)Round upceil(horas)
len(s)String lengthlen(nombre)
upper(s)Uppercaseupper(codigo)
lower(s)Lowercaselower(email)
trim(s)Remove whitespacetrim(nombre)
now()Current date and timenow()
today()Current datetoday()
Creado con Fyso