SpartivoDocs
Open app
Get started
OverviewQuickstartAuthenticationRequests and errors
API reference
RecordsModules and fieldsFilesMessagingDocuments and e-signatureFunctionsWebhooks
Spartivo Script
IntroductionLanguage guideCRM and actionsBuilt-in functionsExamples
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 map
Fetch one record by id.
account = crm.getRecord(record.account);
crm.searchRecords(module, criteria, limit)→ list of record maps
Find 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 map
Create 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 map
Change 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)→ true
Move a record to the recycle bin.
crm.addNote(id, text)→ true
Add a note to the record's timeline.
crm.addNote(record.id, "Synced to ERP");
crm.addTag(id, tag)→ true
Add a tag if the record does not already have it.
crm.removeTag(id, tag)→ true
Remove a tag from a record.
crm.getUsers()→ list of maps
All active users in the workspace, each with id, name, email and role.
crm.getUser(idOrEmail)→ map or null
One 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})→ true
Send 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})→ true
Send 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})→ true
Show 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 id
Create 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 result
Run 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});
Previous← Language guideNextBuilt-in functions →
On this page
How records look in codeCRM recordsActions