Language guide
Everything the language has, on one page. If you have written a little JavaScript, Deluge or Excel formulas, it will feel familiar.
Values and variables
Assign with =. There is nothing to declare, and a variable can hold any kind of value. End each statement with a semicolon.
count = 5;
price = 19.99;
name = "Aisha";
active = true;
nothing = null;
tags = ["vip", "renewal"];
customer = {"name": "Northwind", "tier": "gold"};| Kind | Written as | Notes |
|---|---|---|
| Number | 5, 19.99 | Whole and decimal numbers are the same kind. |
| Text | "hello" or 'hello' | Use \n for a new line and \" for a quote inside the text. |
| True or false | true, false | |
| Nothing | null | An empty field on a record is null. |
| List | [1, 2, 3] | Read an item with list[0] or list.get(0). Counting starts at 0. |
| Map | {"key": "value"} | Read a value with map.key, map["key"] or map.get("key"). |
Operators
| Operators | Meaning |
|---|---|
+ - * / % | Maths. + also joins text, and joins two lists. |
== != | Equal, not equal. 5 == "5" is true: numbers and text are compared by what they show. |
< > <= >= | Compare numbers, or dates in ISO form. |
&& || ! | And, or, not. |
condition ? a : b | Pick a when the condition is true, otherwise b. |
+= -= *= /= | Change a variable in place: total += 10; |
In a condition, null, false, 0 and empty text count as false. Everything else counts as true, including an empty list, so test a list with list.isEmpty() or list.size() > 0.
Conditions
if (record.amount >= 100000) {
tier = "enterprise";
} else if (record.amount >= 20000) {
tier = "mid-market";
} else {
tier = "small";
}Loops
for each walks through a list, or through the keys of a map. while repeats as long as a condition holds. break leaves a loop and continue skips to the next round.
total = 0;
for each deal in deals {
if (deal.stage == "lost") {
continue;
}
total += ifNull(deal.amount, 0);
}
attempt = 0;
while (attempt < 3) {
attempt += 1;
}Returning and logging
return ends the function and hands back a value: text, a number, a list or a map. On a custom button, returned text is shown to the person who clicked. info writes a line to the run log, which you can read in the editor and in the function's run history.
info "Checking " + record.name;
if (isEmpty(record.email)) {
return "No email address on this record";
}
return {"ok": true, "email": record.email};Handling errors
When something fails, for example a record is not found or another system does not answer, the function stops and the run is marked as failed with the line number. Wrap risky steps in try to carry on instead.
try {
res = invokeUrl({"url": "https://api.example.com/stock/" + record.sku});
crm.updateRecord(record.id, {"in_stock": res.body.available});
} catch (e) {
info "Stock check failed: " + e;
crm.addTag(record.id, "stock-check-failed");
}Comments
// A note on one line
/* A longer note
over several lines */Parameters
List parameter names in the function's settings. Each one becomes a variable, and all of them are also in the input map. A parameter that is not passed is null.
limit = ifNull(days, 7);
leads = crm.searchRecords("leads", {"region": region, "status": "new"}, 100);
return leads.size() + " new leads in " + region + " to review within " + limit + " days";Limits
Limits keep one function from slowing the workspace down. When a limit is reached the run stops with a clear message.
| Limit | Per run |
|---|---|
| Steps (statements and loop rounds) | 50,000 |
| Running time | 20 seconds |
| CRM, message and web calls in total | 60 |
Web addresses called with invokeUrl | 5 |
Records returned by one crm.searchRecords | 200 |
| Items in a list | 5,000 |
Lines written with info | 100 |
Functions calling functions with run | 3 levels |
| Code length | 60,000 characters |