Spartivo Script
Examples
Complete functions for common jobs. Field names such as `amount` or `open_pipeline` are examples: use the API names from your own modules.
Flag large deals
Runs from: Workflow rule on Deals, when a deal is created or its amount changes
Spartivo Script
if (record.amount > 100000) {
crm.updateRecord(record.id, {"priority": "high"});
crm.addTag(record.id, "key-deal");
notify({"user": record.ownerId, "title": "Large deal: " + record.name, "record": record.id});
}
return "checked";Roll up open pipeline to the account
Runs from: Custom button on Accounts, or a workflow rule on Deals
Spartivo Script
deals = crm.searchRecords("deals", {"account": record.id}, 200);
total = 0;
for each d in deals {
if (d.stage != "won" && d.stage != "lost") {
total += ifNull(d.amount, 0);
}
}
crm.updateRecord(record.id, {"open_pipeline": total});
return "Open pipeline: " + total;Sync a customer to another system
Runs from: Workflow rule, or called from your own system through the API
Spartivo Script
res = invokeUrl({
"url": "https://api.example.com/customers",
"method": "POST",
"headers": {"Authorization": "Bearer YOUR_TOKEN"},
"body": {"name": record.name, "email": record.email}
});
if (!res.ok) {
return "Sync failed with status " + res.status;
}
crm.updateRecord(record.id, {"external_id": res.body.id});
return "Synced";Follow up on stale leads
Runs from: Scheduled, every day
Spartivo Script
leads = crm.searchRecords("leads", {"status": "new"}, 100);
count = 0;
for each lead in leads {
if (daysBetween(lead.createdAt, now()) >= 3) {
createTask({"subject": "Follow up with " + lead.name, "record": lead.id, "owner": lead.ownerId, "dueInDays": 1});
count += 1;
}
}
return count + " follow-up tasks created";Welcome a new contact on WhatsApp
Runs from: Workflow rule on Contacts, when a contact is created
Spartivo Script
if (isEmpty(record.phone)) {
return "No phone number";
}
try {
sendMessage({"record": record.id, "channel": "whatsapp", "text": "Hello " + record.name + ", thanks for getting in touch."});
crm.addNote(record.id, "Welcome message sent");
} catch (e) {
info e;
return "Message could not be sent";
}
return "Welcomed";