Spartivo Script
CRM and actions
The functions that reach outside your code: records, messages, notifications, tasks and other systems.
How records look in code
A record is a map. Its fields sit next to the built-in properties, so you read record.email and record.ownerId the same way. A lookup field holds the id of the related record; fetch it with crm.getRecord when you need its fields.
Spartivo Script
account = crm.getRecord(record.account);
info record.name + " belongs to " + account.name + ", owned by " + record.owner.name;CRM records
Read and change records. Every call counts towards the limit of calls per run.
crm.getRecord(id)→ record mapFetch one record by id.
account = crm.getRecord(record.account);crm.searchRecords(module, criteria, limit)→ list of record mapsFind records in a module. Criteria is a map of exact matches, or a list of [field, operator, value] rules. Operators: eq, neq, contains, starts_with, gt, gte, lt, lte, in, is_null, not_null. Returns up to 200 records, newest first.
big = crm.searchRecords("deals", [["amount", "gt", 100000], ["stage", "neq", "lost"]], 50);crm.createRecord(module, values)→ record mapCreate a record. The map needs a "name"; ownerId and tags are optional; every other key is a field.
task = crm.createRecord("tasks", {"name": "Call back", "related_to": record.id});crm.updateRecord(id, values)→ record mapChange fields on a record. Only the keys you pass are changed. Workflow rules and validation rules run as usual.
crm.updateRecord(record.id, {"stage": "won"});crm.deleteRecord(id)→ trueMove a record to the recycle bin.
crm.addNote(id, text)→ trueAdd a note to the record's timeline.
crm.addNote(record.id, "Synced to ERP");crm.addTag(id, tag)→ trueAdd a tag if the record does not already have it.
crm.removeTag(id, tag)→ trueRemove a tag from a record.
crm.getUsers()→ list of mapsAll active users in the workspace, each with id, name, email and role.
crm.getUser(idOrEmail)→ map or nullOne user by id or by email address. Null when nobody matches.
Actions
Send messages, notify people, create tasks and talk to other systems.
sendEmail({to, subject, body})→ trueSend an email from the workspace's email sender. The body may contain HTML.
sendEmail({"to": record.email, "subject": "Welcome", "body": "Hello " + record.name});sendMessage({record, channel, text})→ trueSend a WhatsApp, SMS or email message to a record through a connected channel. Channel is "whatsapp", "sms" or "email".
sendMessage({"record": record.id, "channel": "whatsapp", "text": "Your order is ready"});notify({user, title, body, record})→ trueShow a notification to a user in the app. Body and record are optional.
notify({"user": record.ownerId, "title": "Deal needs attention", "record": record.id});createTask({subject, record, owner, dueInDays})→ the new task's idCreate a task. Record links it to a record, owner assigns it, dueInDays sets the due date from today.
createTask({"subject": "Follow up", "record": record.id, "owner": record.ownerId, "dueInDays": 2});invokeUrl({url, method, headers, params, body})→ {status, ok, body, text}Call another system over HTTPS. Method defaults to POST when there is a body, otherwise GET. A map body is sent as JSON. Only public https addresses are allowed and each call waits up to 10 seconds.
res = invokeUrl({"url": "https://api.example.com/orders", "method": "POST", "body": {"id": record.id}});
if (!res.ok) { return "Failed: " + res.status; }run(apiName, args)→ the other function's resultRun another function by its API name and get back what it returns. Functions can be nested up to 3 levels deep.
score = run("score_lead", {"lead": record.id});