The process modeler SDK is available in any input or output variables in the process modeler, It allows users access resources from process and execute complexe computational in the instance run time.
The SDK can be accessed trought the SF variable.
The SDK has the following attributs
var SF = {
collection : Object,
user : Object,
file : Object,
utils : Object,
sql : Object,
instance : Object,
task : Object,
process : Object,
softyTable : Object,
mode : String,
};
In the following sections we will explicit each attribute and the allowed methods.
Since 8.6, a date field without time (a Date picker of type date, dates, daterange, month or year, with Date Only off) stores the chosen day at 12:00 UTC of that day: picking December 25, 2023 stores 2023-12-25T12:00:00.000Z, whatever the time zone of the user. In your scripts (process inputs and outputs, API code, SDK queries), compare days, never midnights:
const moment = SF.utils.moment;
let day = moment.utc(startDate).format('YYYY-MM-DD');
let sameDay = moment.utc(startDate).isSame(moment.utc(endDate), 'day');
let requests = await SF.collection.find('requests', {
startDate: {
$gte: moment.utc(day).startOf('day').toDate(),
$lte: moment.utc(day).endOf('day').toDate()
}
});
Values saved before 8.6 (at local midnight) keep their value until a user picks a new day. See How dates without time are stored.
The utils object has the methods that will allow you to
Generates an incremental number based on a unique string name. The resulting ID can be zero-padded to a specified length if desired.
| Name | Type | Description |
|---|
| name | string | A unique name used as the key to generate the ID. |
| padding | number | (Optional) The number of digits to pad the result with (e.g., 6 → 000001). |
| Type | Description |
|---|
| Promise | A Promise that resolves to the generated ID. |
let id = await SF.utils.nextValue("leave_request");
let id = await SF.utils.nextValue("leave_request",5);
Is a function that executes a local shell command and returns the trimmed output.
| Name | Type | Description |
|---|
cmd | string | The shell command to be executed. |
| Type | Description |
|---|
Promise<{data: string}> | A Promise that resolves to an object containing the trimmed standard output. |
let result = await SF.utils.shellExecLocal('echo Hello World');
let result = await SF.utils.shellExecLocal('pwd');
Is a function that executes a shell command on a remote server.
| Name | Type | Description |
|---|
cdm | string | The shell command to be executed remotely. |
options | object | SSH connection options (host, port, username, password/privateKey, etc.). |
| Type | Description |
|---|
Promise<{data: string, code: number}> | A Promise that resolves to an object containing: – data: The standard output result as a string. – code: The exit code of the remote command. |
let result = await SF.utils.shellExecRemote('ls -l', {
host: '192.168.1.10',
port: 22,
username: 'user',
password: 'password'
});
Axios is a Promise based HTTP client for the browser and node.js
Lean more See the official documentation
let id = SF.utils.axios.get('/data/json/123')
.then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
Allow to insert an array of json in to a collection
| Name | Type | Description |
|---|
collection | string | Collection name in Softyflow. |
data | array | Array of data to be inserted into the collection. |
| Type | Description |
|---|
Promise | A Promise indicating the result of the insert operation. |
await SF.collection.insertMany("cost-centers",[{label : "IT", value : "it"}])
Allow to insert a json in to a collection
| Name | Type | Description |
|---|
collection | string | Collection name in Softyflow. |
data | object | JSON object representing a single value to be inserted into the collection. |
| Type | Description |
|---|
Promise | A Promise indicating the result of the insert operation. |
await SF.collection.insertOne("cost-centers",{label : "IT", value : "it"})
Returns one document that satisfies the specified query criteria . If multiple documents satisfy the query, this method returns the first document.
| Name | Type | Description |
|---|
collection | string | Collection name in Softyflow. |
query | object | JSON object of values to be matched in the collection. |
| Type | Description |
|---|
Promise | Return promise |
await SF.collection.findOne("cost-centers",{value : "it"})
Returns all the documents that satisfies the specified query criteria .
| Name | Type | Description |
|---|
collection | string | Collection name in Softyflow. |
query | object | JSON object representing the criteria to match documents in the collection. |
| Type | Description |
|---|
Promise | A Promise indicating the result of the find operation. |
await SF.collection.find("cost-centers",{value : "it"})
update the first document that satisfies the specified query criteria .
| Name | Type | Description |
|---|
collection | string | Collection name in Softyflow. |
query | object | JSON object representing the criteria to match documents in the collection. |
body | object | JSON object representing the fields and values to update. |
| Type | Description |
|---|
Promise | A Promise indicating the result of the update operation. |
await SF.collection.updateOne("cost-centers",{value : "it"})
update all the documents that satisfies the specified query criteria .
| Name | Type | Description |
|---|
collection | string | Collection name in Softyflow. |
query | object | JSON object representing the value to match in the collection. |
body | object | JSON object representing the value to update in the collection. |
| Type | Description |
|---|
Promise | Returns a promise. |
await SF.collection.update("cost-centers",{value : "it"})
Returns the count of documents in the collection.
| Name | Type | Description |
|---|
collection | string | Collection name in Softyflow. |
| Type | Description |
|---|
Promise | Returns a promise. |
await SF.collection.count("cost-centers")
Allow to delete a document from collection.
| Name | Type | Description |
|---|
collection | string | Collection name in Softyflow. |
query | object | JSON object representing the value to match in the collection. |
| Type | Description |
|---|
Promise | Returns a promise. |
await SF.collection.deleteOne("cost-centers",{value : "it"})
Allow to delete multiple documents from collection. An empty criteria {} deletes every document of the collection.
| Name | Type | Description |
|---|
collection | string | Collection name in Softyflow. |
query | object | JSON object representing the value to match in the collection. |
| Type | Description |
|---|
Promise | Returns a promise. |
await SF.collection.delete("cost-centers",{value : "it"})
Aggregation operations process data records and return computed results
| Name | Type | Description |
|---|
collection | string | Collection name in Softyflow. |
aggregation | array | Aggregation array. |
| Type | Description |
|---|
Promise | Returns a promise. |
let aggregation = [
{
"$match": { "type": "type1" }
},
{
"$project" : {
"_id": 1,
"name": 1
}
}
]
await SF.collection.aggregate("cost-centers", aggregation);
SF.collection.aggregate runs the pipeline directly on the database, with every MongoDB stage: the restrictions that apply since 8.6 to the pipelines sent over HTTP (see the web modeler SDK) do not apply to it. Move a page pipeline that needs a refused stage into SF.collection.aggregate, in a process script or an API.
This is only true for SF.collection.aggregate. SF.report.aggregate (and SF.report.exportToGoogleSheet) calls the report over HTTP (/report/<id>/instances/aggregation) and goes through the same server check as the pages: $out, $merge, $function, $accumulator, $where and the stages that are not read stages are refused (Aggregation refused: …). Only the check of the $lookup / $graphLookup / $unionWith targets is relaxed for the scripts: besides the instances and the tasks, they may read any SoftyFlow collection <name>_<mode> (never users). Moving a refused report pipeline into a script with SF.report.aggregate does not help.
Remove All Documents from a Collection.
| Name | Type | Description |
|---|
collection | string | Collection name in Softyflow. |
| Type | Description |
|---|
Promise | Returns a promise. |
await SF.collection.cleanCollection("cost-centers")
Is a function that performs multiple write operations (insert, update, delete) in a single batch on a specified MongoDB collection.
| Name | Type | Description |
|---|
col | string | The name of the collection (without suffix). |
bulkOps | Array | An array of bulk write operations (insertOne, updateOne, deleteOne, etc.). |
| Type | Description |
|---|
Promise | Returns a Promise that resolves once all bulk operations are complete. |
let bulkOps = [
{ insertOne: { document: { name: 'John', age: 30 } } },
{ updateOne: { filter: { name: 'John' }, update: { $set: { age: 31 } } } },
{ deleteOne: { filter: { name: 'John' } } }
];
await SF.utils.bulkWrite('users', bulkOps);
Get all users in a given group
| Name | Type | Description |
|---|
group | string | Group ID. |
| Type | Description |
|---|
Promise | Returns a promise. |
await SF.user.getUsersinGroup("6042551d231e8c8ade19bc09")
get the users who exist in certain groups.
| Name | Type | Description |
|---|
groups | string[] | Array of groupID. |
| Type | Description |
|---|
Promise | Return promise |
await SF.user.getUsersInGroupList(["6042551d231e8c8ade19bc09","6040e3679c81cf1b60b698f4"])
Is a function that retrieves a group document from the "groups" collection by its unique ID.
| Name | Type | Description |
|---|
id | string | The ID of the group to be retrieved. |
| Type | Description |
|---|
| `Promise<object | null>` |
let group = await SF.utils.getGroupById("60c72b2f9f1b2c3c8f3b8b0b");
let group = await SF.utils.getGroupById("60c72b2f9f1b2c3c8f3b8b0c");
Get user information using his id.
| Name | Type | Description |
|---|
id | string | User ID. |
| Type | Description |
|---|
Promise | Return promise |
await SF.user.getUserById("6042551d231e8c8ade19bc09")
Get user information using his email.
| Name | Type | Description |
|---|
email | string | User email. |
| Type | Description |
|---|
Promise | Return promise |
await SF.user.getUserByMail("jean.dupont@example.com")
Update user information using his ID.
| Name | Type | Description |
|---|
id | string | User ID. |
data | object | JSON object of values to update. |
| Type | Description |
|---|
Promise | Return promise |
await SF.user.updateUserById("6042551d231e8c8ade19bc09",{firstName : "test"})
Update a list of users individualy : to each user their own payload.
| Name | Type | Description |
|---|
Array | Array | Array of objects, each containing a user ID and a payload. |
| Type | Description |
|---|
Promise | Return promise |
await SF.user.updateUsersEach([{ _id: "6042551d231e8c8ade19bc09", payload: { firstName: 'firstUser' } }, { _id: "6042551d231e8c8ade19bc10", payload: { firstName: 'secondUser' } }])
Update user metadata using his ID.
| Name | Type | Description |
|---|
id | string | User ID. |
field | object | JSON object of metadata to update. |
value | object | JSON object of values to be updated. |
| Type | Description |
|---|
Promise | Return promise |
await SF.user.updateUserMetadataById("6042551d231e8c8ade19bc09", "Manager", "test")
Get users informations.
| Type | Description |
|---|
Promise | Return promise |
Get user metadata using his ID.
| Name | Type | Description |
|---|
id | string | User ID. |
| Type | Description |
|---|
Promise | Return promise |
await SF.user.getUserMetadata("6042551d231e8c8ade19bc09")
Add user to a groupe using user ID & group ID.
| Name | Type | Description |
|---|
userId | string | User ID. |
groupid | string | Group ID. |
| Type | Description |
|---|
Promise | Return promise |
await SF.user.addUserToGroup("6042551d231e8c8ade19bc09", "62c2b6f74d16c2a2c19dcdb7")
Remove user from group using user ID & group ID.
| Name | Type | Description |
|---|
userId | string | User ID. |
groupid | string | Group ID. |
| Type | Description |
|---|
Promise | Return promise |
await SF.user.removeUserfromGroup("6042551d231e8c8ade19bc09", "62c2b6f74d16c2a2c19dcdb7")
Allow to create new user.
| Name | Type | Description |
|---|
data | object | JSON content user data |
| Type | Description |
|---|
Promise | Return promise |
This is the allowed user data:
| field | Description |
|---|
| email | Required and Unique. The user email (string) |
| lastName | Required. The user last name (string) |
| firstName | Required. The user first name (string) |
| group | Required. The user production groups ids (array) |
| group_test | Optional. The user test groups ids (array) |
| group_uat | Optional. The user UAT groups ids (array) |
| metadata_test | Optional. The user test metadata (json) |
| metadata_uat | Optional. The user UAT metadata (json) |
| metadata_prod | Optional. The user production metadata (json) |
| ideAccess | Required. IDE access right (boolean) |
| blocked | Optional. User blocking (boolean) |
| sendMail | Optional. Send email notification to the user (boolean) |
| getPassword | Optional. Get the generated password in response (boolean) |
var newUser = {
firstName: "Jean",
lastName: "Martin",
email: "jean.martin@example.com",
group_test: [],
group_uat: [],
group: [],
metadata_test: {},
metadata_uat: {},
metadata_prod: {},
ideAccess: false,
blocked: false,
sendMail: false,
getPassword: false
};
var user = await SF.user.createUser(newUser);
The File class manages files stored in MongoDB's GridFS system, providing methods to upload, retrieve, delete, and generate PDFs from EJS templates.
Retrieve the text content of a file by its ID.
| Name | Type | Description |
|---|
id | string | File ObjectId |
encoding | string | Encoding to use (default: 'utf8') |
| Type | Description |
|---|
Promise<object> | File metadata with content field |
let result = await SF.file.getFileContentById("64bfa28cfabc123...", "utf8");
console.log(result.content);
Retrieve the binary content of a file as a Buffer.
| Name | Type | Description |
|---|
id | string | File ObjectId |
| Type | Description |
|---|
Promise<Buffer> | File data as Buffer |
let buffer = await SF.file.getFileBufferById("64bfa28cfabc123...");
Generate a PDF from a stored EJS template file and save it back to GridFS.
| Name | Type | Description |
|---|
dump_var | any | Not used |
fid | string | Template file ID |
context | object | PDF generation context |
| Type | Description |
|---|
Promise<object> | Metadata of saved PDF file |
context.variables: Variables injected into the template.context.SF_pdfName: Optional name for the generated PDF.
The template must be a private file: with a public file as template, the call fails with the error Generation from a public file is not allowed.
await SF.file.generatePDFFromTemplate(null, 'templateId', {
variables: { name: "John" },
SF_pdfName: "user-report.pdf"
});
Create and upload a file from a Buffer.
| Name | Type | Description |
|---|
fileMetadata | object | Metadata (filename, contentType, etc.) |
bufferContent | Buffer | Binary content of the file |
| Type | Description |
|---|
Promise<object> | Metadata of saved file |
await SF.file.createFileFromBuffer({ filename: "doc.txt", contentType: "text/plain" }, Buffer.from("Hello"));
Fill a document template (Word, Excel, LibreOffice, etc.) with data using the Carbone rendering engine. This method takes a template file stored in the database, merges it with the provided data, and creates a new filled document.
| Name | Type | Description |
|---|
id | string | Template file ObjectId |
data | object | JSON data to inject into the template |
| Type | Description |
|---|
Promise<string> | File ID of the newly created filled document |
To create templates compatible with this method:
- Use standard office software (Microsoft Office, LibreOffice, OpenOffice)
- Insert placeholders using the Carbone syntax:
{d.fieldName} - Supported formats: DOCX, XLSX, PPTX, ODT, ODS, ODP, and more
For detailed information on template creation and advanced features (loops, conditions, formatters), see the official Carbone documentation.
Keep the template private: with a public file as template, the call fails with the error Generation from a public file is not allowed.
let data = {
customerName: "John Doe",
amount: 1500,
date: "2025-01-15",
items: [
{ product: "Widget A", quantity: 5, price: 100 },
{ product: "Widget B", quantity: 10, price: 50 }
]
};
let filledDocumentId = await SF.file.fillTemplate("64bfa28cfabc123...", data);
console.log("Filled document ID:", filledDocumentId);
The Carbone engine supports advanced features:
- Loops: Repeat sections for arrays of data
- Conditions: Show/hide content based on data
- Formatters: Format dates, numbers, text
- Nested objects: Access nested data structures
- Calculations: Perform calculations in templates
Example template with loops:
Invoice Items:
{d.items[i].product} - Qty: {d.items[i].quantity} - Price: {d.items[i].price}
For more information, visit Carbone.io Documentation.
Is a function that deletes a file from the database by its unique ID.
| Name | Type | Description |
|---|
id | string | The ID of the file to be deleted. |
| Type | Description |
|---|
Promise<object> | Resolves to an object indicating deletion status: { deleted: 1 } if successful, { deleted: 0 } if failed. |
let result = await SF.file.deleteFileById("60c72b2f9f1b2c3c8f3b8b0b");
let result = await SF.file.deleteFileById("60c72b2f9f1b2c3c8f3b8b0c");
SF.sql works on the external data sources (EDS) of the platform, in the environment of the instance (TEST, UAT or PROD). The criteria of a method can be a SQL condition written as a string ("code='MMA'") or an object whose keys are columns ({ code: 'MMA' }, the conditions are joined with AND).
Rules checked by the server since 8.6:
- EDS not configured in the environment: if the EDS has no connection for the environment of the instance, every call fails with the error
EDS "<name>" is not configured in UAT (or TEST, PROD) instead of an internal error. - Update and delete need a selection: on a SQL database (MySQL, PostgreSQL, Oracle Database, Microsoft SQL Server, Snowflake), an
update or a delete whose criteria are empty (an empty string, an empty object, or an object whose values are all undefined, such as { id: row._id } on a row that has id but no _id) is refused, nothing is changed: Empty selection: the update was not executed (a query selecting the record(s) is required; to update every row on purpose, use the string query "1=1"). To target every row on purpose, pass the string "1=1".
Insert a row into your SQL Table
| Name | Type | Description |
|---|
id | string | Database ID. |
name | string | Table name. |
data | object | Data to insert into database. |
| Type | Description |
|---|
object | Return object |
await SF.sql.insertOne("610c0343f6ebc7ddcb49cc3b", "client", {
code: 'MMA',
codepostal: 225
})
Insert an array of rows into your SQL Table
| Name | Type | Description |
|---|
id | string | Database ID. |
name | string | Table name. |
data | array | Data to insert into database. |
| Type | Description |
|---|
object | Return object |
await SF.sql.insertMany("610c0343f6ebc7ddcb49cc3b", "client", [{
code: 'MMA',
codepostal: 225
}])
Find data in your SQL table.
| Name | Type | Description |
|---|
id | string | Database ID. |
name | string | Table name. |
data | string | Criteria to query database. |
| Type | Description |
|---|
object | Return object |
await SF.sql.findOne("610c0343f6ebc7ddcb49cc3b", "client", "code='MGMT'")
Find all rows in your SQL table that match a certain criteria.
| Name | Type | Description |
|---|
id | string | Database ID. |
name | string | Table name. |
options | object | query: criteria (string or object); optional sortby (column); with sortby, limit and page page the result (without sortby, they are ignored). |
| Type | Description |
|---|
object | Return object |
await SF.sql.find("610c0343f6ebc7ddcb49cc3b", "client", { query: "code='MGMT'" })
await SF.sql.find("610c0343f6ebc7ddcb49cc3b", "client", { query: { city: 'Paris' }, sortby: 'name', limit: 20, page: 0 })
- Sort order: in a process script, the rows are always sorted in descending order on
sortby; a direction option has no effect (direction: 1 does not give an ascending order). To get an ascending order, sort the returned array in the script, or use execute with your own ORDER BY. - Microsoft SQL Server: only the offset is applied (
OFFSET <limit × page> ROWS): limit does not cut the result, every row after the offset is returned.
Update data in your database.
| Name | Type | Description |
|---|
id | string | Database ID. |
name | string | Table name. |
data | string or object | Criteria selecting the rows to update (required on a SQL database, see above). |
newData | object | Updated data. |
| Type | Description |
|---|
object | Return object |
await SF.sql.update("610c0343f6ebc7ddcb49cc3b", "client", "code='MDMS'", {
code: 'CLEA'
})
await SF.sql.update("610c0343f6ebc7ddcb49cc3b", "client", { code: 'MDMS' }, { code: 'CLEA' })
await SF.sql.update("610c0343f6ebc7ddcb49cc3b", "client", "1=1", { active: 0 })
An empty selection ("", {} or { id: undefined }) is refused with Empty selection: the update was not executed … and no row changes.
Delete rows from your database.
| Name | Type | Description |
|---|
id | string | Database ID. |
name | string | Table name. |
data | string or object | Criteria selecting the rows to delete (required on a SQL database, see above). |
| Type | Description |
|---|
object | Return object |
await SF.sql.delete("610c0343f6ebc7ddcb49cc3b", "client", "code='CLEA'")
await SF.sql.delete("610c0343f6ebc7ddcb49cc3b", "client", "1=1")
An empty selection ("", {} or { id: undefined }) is refused with Empty selection: the delete was not executed … and no row is deleted.
count rows in your database.
| Name | Type | Description |
|---|
id | string | Database ID. |
name | string | Table name. |
data | string | Criteria to query database. |
| Type | Description |
|---|
object | Return object |
await SF.sql.count("610c0343f6ebc7ddcb49cc3b", "client", "code='CLEA'")
Execute custom/complex statements on your database.
| Name | Type | Description |
|---|
id | string | Database ID. |
query | string | SQL statement. |
| Type | Description |
|---|
object | Return object |
await SF.sql.execute('610c0343f6ebc7ddcb49cc3b', "DELETE FROM client WHERE code='KL'")
Initiate an existing process.
| Name | Type | Description |
|---|
processId | string | Process ID. |
models | object | Optional. Variables of the new instance. |
options | object | Optional. { onBehalfOf: SF_initiator } starts the process on behalf of the user who calls the API, when the process has the Start by an API on behalf of the caller setting. |
Without onBehalfOf, nothing changes. With it, the process stays closed to everyone else: the rights checked are those of the caller, read again in the current environment, and the instance belongs to them.
| Type | Description |
|---|
object | Return object |
await SF.instance.launchProcess('610c0343f6ebc7ddcb49cc3b')
await SF.instance.launchProcess('610c0343f6ebc7ddcb49cc3b', { amount: 120 }, { onBehalfOf: SF_initiator })
Find one instance that satisfies the specified query criteria.
| Name | Type | Description |
|---|
query | object | JSON object of criteria to match the instance. |
| Type | Description |
|---|
Promise | Return promise |
await SF.instance.findOne({ status: 'Running' })
ObjectId is not available in a script, and the query is passed to MongoDB as it is: an _id written as a string matches nothing. For an id, use the methods by id: SF.instance.pendingTask, SF.instance.getMeasures, SF.task.deleteTaskById.
Find all instances that satisfy the specified query criteria.
| Name | Type | Description |
|---|
query | object | JSON object of criteria to match instances. |
| Type | Description |
|---|
Cursor | A MongoDB cursor, not a list: call .toArray() on it to get the instances. |
const instances = await SF.instance.find({ status: 'Running' }).toArray()
Get Instance latest Pending Task
| Name | Type | Description |
|---|
instanceId | string | Instance ID. |
| Type | Description |
|---|
object | Return object |
await SF.instance.pendingTask('610c0343f6ebc7ddcb49cc3b')
Get Instance Measures
| Name | Type | Description |
|---|
instanceId | string | Instance ID. |
| Type | Description |
|---|
object | Return object |
await SF.instance.getMeasures('610c0343f6ebc7ddcb49cc3b')
Validate Task.
| Name | Type | Description |
|---|
taskId | string | Task ID. |
variables | object | JSON of variables. |
| Type | Description |
|---|
object | Return object |
let variables = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await SF.instance.validateTask('610c0343f6ebc7ddcb49cc3b',variables)
Update variables using instance ID.
| Name | Type | Description |
|---|
Id | string | Instance ID. |
data | object | JSON of variables data. |
| Type | Description |
|---|
object | Return object |
let data = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await SF.instance.updateVariablesById('610c0343f6ebc7ddcb49cc3b',data)
Is a function that links a child instance to a father instance in the "instances" collection, based on a specific activity step.
| Name | Type | Description |
|---|
fatherId | string | The ID of the father instance. |
childId | string | The ID of the child instance to be attached. |
stepId | string | The step ID representing the activity in the father instance. |
| Type | Description |
|---|
Promise<object> | Resolves to { done: true } if the attachment is successful. |
let result = await SF.utils.attachChildInstance(
"661e9d8a1a2b2f7f8d3c4e1f",
"661e9d9b2b5e2f8f8d3c5f0a",
"step123"
);
Is a function that retrieves an instance document by its ID, with an optional projection to select specific fields.
| Name | Type | Description |
|---|
instanceId | string | The ID of the instance to retrieve. |
projection | object | (Optional) MongoDB projection to specify which fields to return. |
| Type | Description |
|---|
Promise<object \| null> | Resolves to the instance document if found, or null if not found. |
let instance = await SF.utils.getVariablesById("661e9d8a1a2b2f7f8d3c4e1f");
let instance = await SF.utils.getVariablesById("661e9d8a1a2b2f7f8d3c4e1f", { variables: 1 });
Deletes an instance by its ID, and also removes all related histories, tasks, and instancelights associated with that instance.
| Name | Type | Description |
|---|
id | string | The ID of the instance to be deleted. |
| Type | Description |
|---|
Promise<object> | Resolves to { done: true } if the deletion is successful. |
let result = await SF.instance.deleteInstanceById("661e9d8a1a2b2f7f8d3c4e1f");
Deletes multiple instances and instancelights associated with a given process ID and an additional query. This method does NOT delete related tasks and histories for performance reasons.
| Name | Type | Description |
|---|
processId | string | The ID of the process whose instances should be deleted. |
query | object | Additional query parameters to filter which instances to delete. |
| Type | Description |
|---|
Promise<object> | Resolves to { done: true } if successful. |
let result = await SF.instance.deleteManyInstances("661e9d8a1a2b2f7f8d3c4e1f", { status: "End" });
await SF.instance.deleteManyInstances("661e9d8a1a2b2f7f8d3c4e1f", { createdAt: { $lt: SF.utils.moment().subtract(5, 'days') } })
Deletes multiple instances with all their related data (tasks, histories, and instancelights) associated with a given process ID and query. This is a complete cleanup operation.
| Name | Type | Description |
|---|
processId | string | The ID of the process whose instances should be deleted. |
query | object | Additional query parameters to filter which instances to delete. |
| Type | Description |
|---|
Promise<object> | Resolves to { done: true } if successful. |
let result = await SF.instance.deleteManyInstancesWithTasksAndHistories(
"661e9d8a1a2b2f7f8d3c4e1f",
{ status: "End" }
);
let result = await SF.instance.deleteManyInstancesWithTasksAndHistories(
"661e9d8a1a2b2f7f8d3c4e1f",
{ createdAt: { $lt: new Date('2024-01-01') } }
);
Is a function that updates the variables of an instance, recalculates related measures based on the process definition, and updates them both in the instance and the last related task.
| Name | Type | Description |
|---|
id | string | The ID of the instance to update. |
data | object | Key-value pairs of variables to update inside the instance. |
| Type | Description |
|---|
Promise<object> | Resolves to { done: true } if the update succeeds. |
let result = await SF.instance.updateInstanceVariables("661e9d8a1a2b2f7f8d3c4e1f", {
amount: 1500,
dueDate: "2025-05-30"
});
The SoftyTable SDK provides methods to interact with SoftyTable resources, allowing you to perform CRUD operations, execute queries, and manage table data.
The SoftyTable is available as a direct instance on the SF object. All methods take the table ID as the first parameter:
await SF.softyTable.list('tableId123', criteria);
The methods call the SoftyTables API of the server, in the environment of the instance. When a call is refused, the promise is rejected with the server error { message } (for updateMany and retrieve, with the HTTP error itself: the message is in error.response.data.err.message).
- Rows read:
list and retrieve return, for each foreign key (many-to-one relation), the parent row in <column>_record, with all its columns (also when a lookup column reads one of them). A single select returns its option in <column>_option; a multiple select returns the option ids in <column> and the options in <column>_options. retrieve also returns, for each many-to-many relation, the ids of the linked rows in <column>: a row read, changed and saved back keeps its links. - Stable paging:
list sorts by the requested column, then by id: rows with the same value keep their order from one page to the next. - Mass changes need a criteria:
updateMany and deleteMany refuse an empty criteria ({}, missing, { $or: [{}] }, { $and: [] }) with A criteria is required to update many rows or A criteria is required to delete many rows, use clear to delete all rows, and change nothing. Use clear to empty a table; to update every row on purpose, pass an explicit criteria such as { id: { $gt: 0 } }. - Columns not published yet: in UAT and PROD,
create, createMany, update and updateMany refuse a value for a column that exists in TEST but is not yet published in that environment: <column> : this column is not published in uat, publish the table in uat to save its value. An empty value is accepted. Publish the table in that environment first. - Readable database errors: the errors of the database come back as clear messages, for example
email = jean.dupont@example.com : this value is already used by another row (unique column), client_id = 42 : the linked row does not exist (foreign key), This row is linked to rows of the table invoices : delete or detach them first (delete of a parent row) or amount : invalid value "abc", integer expected.
Retrieve rows from a SoftyTable with optional filtering, sorting, and pagination.
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
criteria | object | Query criteria with optional where, attributes, include, group, etc. (default: {}) |
limit | number | Maximum number of rows to return (default: 100) |
page | number | Page number for pagination (default: 0) |
sortby | string | Field name to sort by (default: 'createdAt') |
direction | number | Sort direction: 1 for ASC, -1 for DESC (default: 1) |
order | array | Custom order array, e.g., [['field', 'ASC']] (default: null) |
| Type | Description |
|---|
Promise | Resolves to an array of table rows |
let rows = await SF.softyTable.list('610c0343f6ebc7ddcb49cc3b');
let activeRows = await SF.softyTable.list(
'610c0343f6ebc7ddcb49cc3b',
{ where: { status: 'active' } },
50,
0,
'createdAt',
-1
);
let rows = await SF.softyTable.list(
'610c0343f6ebc7ddcb49cc3b',
{
where: { age: { $gte: 18 } },
attributes: ['name', 'email', 'age']
},
20,
0
);
Count the number of rows in a SoftyTable with optional filtering.
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
criteria | object | Query criteria with optional where clause (default: {}) |
| Type | Description |
|---|
Promise | Resolves to an object with count property |
let result = await SF.softyTable.count('610c0343f6ebc7ddcb49cc3b');
let result = await SF.softyTable.count(
'610c0343f6ebc7ddcb49cc3b',
{ where: { status: 'active' } }
);
Create a single row in a SoftyTable.
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
data | object | The data object to insert as a row |
| Type | Description |
|---|
Promise | Resolves to the created row data |
let newRow = await SF.softyTable.create(
'610c0343f6ebc7ddcb49cc3b',
{
name: 'John Doe',
email: 'john@example.com',
age: 30,
status: 'active'
}
);
In UAT and PROD, a value for a column not yet published in that environment is refused (… is not published in uat); a duplicate or invalid value is refused with a clear message (see Behaviour since 8.6).
Create multiple rows in a SoftyTable at once.
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
data | array | Array of data objects to insert |
| Type | Description |
|---|
Promise | Resolves to an array of created rows |
let newRows = await SF.softyTable.createMany(
'610c0343f6ebc7ddcb49cc3b',
[
{ name: 'John Doe', email: 'john@example.com', age: 30 },
{ name: 'Jane Smith', email: 'jane@example.com', age: 25 },
{ name: 'Bob Johnson', email: 'bob@example.com', age: 35 }
]
);
Retrieve a single row from a SoftyTable by its ID.
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
rowId | string | The ID of the row |
| Type | Description |
|---|
Promise | Resolves to the row data, with <fk>_record (parent row of each foreign key) and, for each many-to-many relation, the ids of the linked rows in <column> |
let row = await SF.softyTable.retrieve('610c0343f6ebc7ddcb49cc3b', '12345');
Update a single row in a SoftyTable by its ID.
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
rowId | string | The ID of the row to update |
data | object | The fields and values to update |
| Type | Description |
|---|
Promise | Resolves to the updated row |
let updated = await SF.softyTable.update(
'610c0343f6ebc7ddcb49cc3b',
'12345',
{
status: 'inactive',
updatedAt: new Date()
}
);
Only the fields you send are changed. In UAT and PROD, a value for a column not yet published in that environment is refused (… is not published in prod).
Update multiple rows in a SoftyTable that match specific criteria.
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
criteria | object | Filter on the columns, written directly (no where key), for example { status: 'pending' }. Required: an empty criteria is refused |
data | object | The fields and values to update |
| Type | Description |
|---|
Promise | Resolves to update operation result |
let result = await SF.softyTable.updateMany(
'610c0343f6ebc7ddcb49cc3b',
{ status: 'pending' },
{ status: 'active', processedAt: new Date() }
);
await SF.softyTable.updateMany(
'610c0343f6ebc7ddcb49cc3b',
{ id: { $gt: 0 } },
{ archived: true }
);
Since 8.6, an empty criteria ({}, missing, { $or: [{}] }, { $and: [] }) is refused with A criteria is required to update many rows and no row changes. In UAT and PROD, a value for a column not yet published in that environment is refused.
Delete a single row from a SoftyTable by its ID.
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
rowId | string | The ID of the row |
| Type | Description |
|---|
Promise | Resolves to deletion result |
await SF.softyTable.delete('610c0343f6ebc7ddcb49cc3b', '12345');
Delete multiple rows from a SoftyTable that match specific criteria.
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
criteria | object | Filter on the columns, written directly (no where key). Required: an empty criteria is refused |
| Type | Description |
|---|
Promise | Resolves to deletion result |
await SF.softyTable.deleteMany(
'610c0343f6ebc7ddcb49cc3b',
{ status: 'inactive' }
);
await SF.softyTable.deleteMany(
'610c0343f6ebc7ddcb49cc3b',
{ createdAt: { $lt: new Date('2024-01-01') } }
);
Since 8.6, an empty criteria ({}, missing, { $or: [{}] }, { $and: [] }) is refused with A criteria is required to delete many rows, use clear to delete all rows and nothing is deleted: to empty the table, use clear.
Clear all rows from a SoftyTable (delete all data).
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
| Type | Description |
|---|
Promise | Resolves to deletion result |
await SF.softyTable.clear('610c0343f6ebc7ddcb49cc3b');
Retrieve options for select fields in a SoftyTable.
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
optionsId | string | The ID of the options field |
| Type | Description |
|---|
Promise | Resolves to array of options |
let options = await SF.softyTable.getOptions(
'610c0343f6ebc7ddcb49cc3b',
'status_field'
);
List rows from a joined table (many-to-many relationship).
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
joinTableId | string | The ID of the join table field |
criteria | object | Query criteria with optional where clause (default: {}) |
limit | number | Maximum number of rows to return (default: 100) |
page | number | Page number for pagination (default: 0) |
sortby | string | Field name to sort by (default: 'createdAt') |
direction | number | Sort direction: 1 for ASC, -1 for DESC (default: 1) |
order | array | Custom order array (default: null) |
| Type | Description |
|---|
Promise | Resolves to an array of joined rows |
let relatedItems = await SF.softyTable.joinTableList(
'610c0343f6ebc7ddcb49cc3b',
'related_products'
);
let items = await SF.softyTable.joinTableList(
'610c0343f6ebc7ddcb49cc3b',
'related_products',
{ where: { category: 'electronics' } },
20,
0,
'price',
-1
);
Count rows from a joined table (many-to-many relationship).
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
joinTableId | string | The ID of the join table field |
criteria | object | Query criteria with optional where clause (default: {}) |
| Type | Description |
|---|
Promise | Resolves to an object with count |
let result = await SF.softyTable.joinTableCount(
'610c0343f6ebc7ddcb49cc3b',
'related_products'
);
let result = await SF.softyTable.joinTableCount(
'610c0343f6ebc7ddcb49cc3b',
'related_products',
{ where: { category: 'electronics' } }
);
Execute a custom SQL query on the SoftyTable.
Name a table with @table(<table>): the server replaces it with the table of the current environment ("my_table_sf_test" in TEST, "my_table_sf_prod" in PROD). A name that is not a SoftyTable, or a table not deployed in this environment, is refused with an error.
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
query | string | The SQL query to execute |
options | object | Query options with replacements and type (default: {}) |
| Field | Type | Description |
|---|
replacements | object | Values to replace in parameterized queries |
type | string | Query type: 'SELECT', 'INSERT', 'UPDATE', 'DELETE', 'RAW', 'SHOWTABLES' |
| Type | Description |
|---|
Promise | Resolves to the query results |
let results = await SF.softyTable.execute(
'610c0343f6ebc7ddcb49cc3b',
'SELECT * FROM @table(my_table) WHERE status = :status',
{
replacements: { status: 'active' },
type: 'SELECT'
}
);
let results = await SF.softyTable.execute(
'610c0343f6ebc7ddcb49cc3b',
`UPDATE @table(my_table) SET status = 'processed' WHERE "createdAt" < NOW() - INTERVAL '30 days'`,
{ type: 'UPDATE' }
);
Migrate rows in a SoftyTable (for data migration operations).
| Name | Type | Description |
|---|
tableId | string | The ID of the SoftyTable |
migrationData | object | Migration configuration data |
| Type | Description |
|---|
Promise | Resolves to migration result |
let result = await SF.softyTable.migrate(
'610c0343f6ebc7ddcb49cc3b',
{
}
);
The Task SDK provides methods to interact with task resources, allowing you to query, update, save, and delete tasks.
Find one task that satisfies the specified query criteria.
| Name | Type | Description |
|---|
query | object | JSON object of criteria to match the task. |
| Type | Description |
|---|
Promise | Return promise |
await SF.task.findOne({ status: 'End' })
ObjectId is not available in a script, and the query is passed to MongoDB as it is: an _id written as a string matches nothing. For an id, use the methods by id: SF.instance.pendingTask, SF.instance.getMeasures, SF.task.deleteTaskById.
Find all tasks that satisfy the specified query criteria.
| Name | Type | Description |
|---|
query | object | JSON object of criteria to match tasks. |
| Type | Description |
|---|
Cursor | A MongoDB cursor, not a list: call .toArray() on it to get the tasks. |
const tasks = await SF.task.find({ status: 'Running' }).toArray()
Delete a task by its ID.
| Name | Type | Description |
|---|
id | string | Task ID. |
| Type | Description |
|---|
Promise | Return promise |
await SF.task.deleteTaskById('610c0343f6ebc7ddcb49cc3b')
Delete multiple tasks that match the specified query criteria.
| Name | Type | Description |
|---|
query | object | JSON object of criteria to match tasks. |
| Type | Description |
|---|
Promise | Return promise |
await SF.task.deleteMany({ status: 'End' })
Delete all history records associated with a specific task.
| Name | Type | Description |
|---|
taskId | string | Task ID. |
| Type | Description |
|---|
Promise | Return promise |
await SF.task.deleteHistoryByTaskId('610c0343f6ebc7ddcb49cc3b')
Delete all history records associated with a specific instance.
| Name | Type | Description |
|---|
instanceId | string | Instance ID. |
| Type | Description |
|---|
Promise | Return promise |
await SF.task.deleteHistoryByInstanceId('610c0343f6ebc7ddcb49cc3b')
Delete history records that match the specified query criteria.
| Name | Type | Description |
|---|
query | object | JSON object of criteria to match histories. |
| Type | Description |
|---|
Promise | Return promise |
await SF.task.deleteHistory({ action: 'task_completed' })
await SF.task.deleteHistory({ createdAt: { $lt: new Date('2024-01-01') } })
Save a task with updated data.
| Name | Type | Description |
|---|
taskId | string | Task ID. |
body | object | Variables to save as a draft on the task (stored in savedVariables, the task stays open). |
| Type | Description |
|---|
Promise | Return promise |
await SF.task.saveTask('610c0343f6ebc7ddcb49cc3b', {
comment: 'To be reviewed on Monday'
})
Update a task by its ID.
| Name | Type | Description |
|---|
id | string | Task ID. |
data | object | JSON object of values to update. |
| Type | Description |
|---|
Promise | Return promise |
await SF.task.updateTask('610c0343f6ebc7ddcb49cc3b', {
description: 'Waiting for the supplier',
dueDate: new Date('2026-12-31')
})
The values are written directly on the task, without the engine: writing status does not complete the task and does not move the instance forward. The engine keeps a task in Running, then sets it to End when it is validated. To complete a task, use SF.instance.validateTask.
Change who receives the open tasks (status Running) of one or more processes, in the environment the script runs in: replace a user or a role by another, or remove a user or a role. Only the tasks change: the users, the role members, the process versions, the completed tasks and the history are not modified.
SF.task.replaceUser({ from, to, processes, query })
SF.task.replaceRole({ from, to, processes, query })
SF.task.deleteUser({ from, processes, query })
SF.task.deleteRole({ from, processes, query })
| Method | What changes on each task |
|---|
replaceUser | from is replaced by to in the assignees and the observers. |
replaceRole | the role from is replaced by the role to. |
deleteUser | from is removed from the assignees and the observers. |
deleteRole | the role from is removed. |
One object:
| Name | Type | Description |
|---|
from | string | Required. The user's e-mail (replaceUser, deleteUser) or the role ID (replaceRole, deleteRole). E-mails match whatever their case. |
to | string | Required for replaceUser and replaceRole. The new user's e-mail or the new role ID. It must exist. |
processes | string[] | Required. IDs of the processes whose open tasks are changed. |
query | object | Optional. MongoDB query on the task document, added to the filter above: createdAt, dueDate, name, priority, measures.<key>… It can only narrow the selection ($where and $function are refused). |
| Type | Description |
|---|
Promise | { matched, modified, tasks, skipped }: tasks found, tasks changed, IDs of the changed tasks, IDs of the tasks left untouched. |
There is no mode option: a script running in TEST only changes the TEST tasks, one running in PROD only the PROD tasks. A call with mode is refused.
deleteUser and deleteRole never leave a task without anyone: a task that would have no assignee and no role is not changed, and its ID is returned in skipped.
await SF.task.replaceUser({
from: 'ali@acme.com',
to: 'sara@acme.com',
processes: ['6aeca4b1f6ebc7ddcb49cc3b', '6aeca4c2f6ebc7ddcb49cc3b']
})
await SF.task.replaceRole({
from: '610c0343f6ebc7ddcb49cc3b',
to: '610c0343f6ebc7ddcb49cc3c',
processes: ['6aeca4b1f6ebc7ddcb49cc3b'],
query: { createdAt: { $gte: new Date('2026-11-01') }, 'measures.amount': { $gt: 1000 } }
})
const result = await SF.task.deleteRole({ from: '610c0343f6ebc7ddcb49cc3b', processes: ['6aeca4b1f6ebc7ddcb49cc3b'] })