Skip to main content

Process modeler SDK

The process modeler SDK DescriptionDirect link to The process modeler SDK Description

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, // SoftyTable instance with methods to interact with tables
  mode : String, // The current Mode this is setted automatically
};

In the following sections we will explicit each attribute and the allowed methods.

Dates entered in formsDirect link to Dates entered in forms

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;
// The day chosen in the form (YYYY-MM-DD)
let day = moment.utc(startDate).format('YYYY-MM-DD');
// Same day?
let sameDay = moment.utc(startDate).isSame(moment.utc(endDate), 'day');
// Every request of that day (from 00:00 to 23:59 UTC)
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.

1 - UtilsDirect link to 1 - Utils


The utils object has the methods that will allow you to

nextValueDirect link to nextValue

Generates an incremental number based on a unique string name. The resulting ID can be zero-padded to a specified length if desired.

ParametersDirect link to Parameters

NameTypeDescription
namestringA unique name used as the key to generate the ID.
paddingnumber(Optional) The number of digits to pad the result with (e.g., 6 → 000001).

ReturnsDirect link to Returns

TypeDescription
PromiseA Promise that resolves to the generated ID.

ExamplesDirect link to Examples

let id = await SF.utils.nextValue("leave_request");
// return number 1
let id = await SF.utils.nextValue("leave_request",5);
// return string 00001

shellExecLocalDirect link to shellExecLocal

Is a function that executes a local shell command and returns the trimmed output.

ParametersDirect link to Parameters

NameTypeDescription
cmdstringThe shell command to be executed.

ReturnsDirect link to Returns

TypeDescription
Promise<{data: string}>A Promise that resolves to an object containing the trimmed standard output.

ExamplesDirect link to Examples

let result = await SF.utils.shellExecLocal('echo Hello World');
// returns: { data: 'Hello World' }

let result = await SF.utils.shellExecLocal('pwd');
// returns: { data: '/home/user/project' }

shellExecRemoteDirect link to shellExecRemote

Is a function that executes a shell command on a remote server.

ParametersDirect link to Parameters

NameTypeDescription
cdmstringThe shell command to be executed remotely.
optionsobjectSSH connection options (host, port, username, password/privateKey, etc.).

ReturnsDirect link to Returns

TypeDescription
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.

ExamplesDirect link to Examples

let result = await SF.utils.shellExecRemote('ls -l', {
  host: '192.168.1.10',
  port: 22,
  username: 'user',
  password: 'password'
});
// returns: { data: 'list of files and folders...', code: 0 }

axiosDirect link to axios

Axios is a Promise based HTTP client for the browser and node.js Lean more See the official documentation

ExamplesDirect link to Examples

let id = SF.utils.axios.get('/data/json/123')
  .then(function (response) {
    // handle success
    console.log(response);
  }).catch(function (error) {
    // handle error
    console.log(error);
  });

2 - CollectionDirect link to 2 - Collection


insertManyDirect link to insertMany

Allow to insert an array of json in to a collection

ParametersDirect link to Parameters

NameTypeDescription
collectionstringCollection name in Softyflow.
dataarrayArray of data to be inserted into the collection.

ReturnsDirect link to Returns

TypeDescription
PromiseA Promise indicating the result of the insert operation.

ExamplesDirect link to Examples

await SF.collection.insertMany("cost-centers",[{label : "IT", value : "it"}])

insertOneDirect link to insertOne

Allow to insert a json in to a collection

ParametersDirect link to Parameters

NameTypeDescription
collectionstringCollection name in Softyflow.
dataobjectJSON object representing a single value to be inserted into the collection.

ReturnsDirect link to Returns

TypeDescription
PromiseA Promise indicating the result of the insert operation.

ExamplesDirect link to Examples

await SF.collection.insertOne("cost-centers",{label : "IT", value : "it"})

findOneDirect link to findOne

Returns one document that satisfies the specified query criteria . If multiple documents satisfy the query, this method returns the first document.

ParametersDirect link to Parameters

NameTypeDescription
collectionstringCollection name in Softyflow.
queryobjectJSON object of values to be matched in the collection.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.collection.findOne("cost-centers",{value : "it"})

findDirect link to find

Returns all the documents that satisfies the specified query criteria .

ParametersDirect link to Parameters

NameTypeDescription
collectionstringCollection name in Softyflow.
queryobjectJSON object representing the criteria to match documents in the collection.

ReturnsDirect link to Returns

TypeDescription
PromiseA Promise indicating the result of the find operation.

ExamplesDirect link to Examples

await SF.collection.find("cost-centers",{value : "it"})

updateOneDirect link to updateOne

update the first document that satisfies the specified query criteria .

ParametersDirect link to Parameters

NameTypeDescription
collectionstringCollection name in Softyflow.
queryobjectJSON object representing the criteria to match documents in the collection.
bodyobjectJSON object representing the fields and values to update.

ReturnsDirect link to Returns

TypeDescription
PromiseA Promise indicating the result of the update operation.

ExamplesDirect link to Examples

await SF.collection.updateOne("cost-centers",{value : "it"})

updateDirect link to update

update all the documents that satisfies the specified query criteria .

ParametersDirect link to Parameters

NameTypeDescription
collectionstringCollection name in Softyflow.
queryobjectJSON object representing the value to match in the collection.
bodyobjectJSON object representing the value to update in the collection.

ReturnsDirect link to Returns

TypeDescription
PromiseReturns a promise.

ExamplesDirect link to Examples

await SF.collection.update("cost-centers",{value : "it"})

countDirect link to count

Returns the count of documents in the collection.

ParametersDirect link to Parameters

NameTypeDescription
collectionstringCollection name in Softyflow.

ReturnsDirect link to Returns

TypeDescription
PromiseReturns a promise.

ExamplesDirect link to Examples

await SF.collection.count("cost-centers")

deleteOneDirect link to deleteOne

Allow to delete a document from collection.

ParametersDirect link to Parameters

NameTypeDescription
collectionstringCollection name in Softyflow.
queryobjectJSON object representing the value to match in the collection.

ReturnsDirect link to Returns

TypeDescription
PromiseReturns a promise.

ExamplesDirect link to Examples

await SF.collection.deleteOne("cost-centers",{value : "it"})

deleteDirect link to delete

Allow to delete multiple documents from collection. An empty criteria {} deletes every document of the collection.

ParametersDirect link to Parameters

NameTypeDescription
collectionstringCollection name in Softyflow.
queryobjectJSON object representing the value to match in the collection.

ReturnsDirect link to Returns

TypeDescription
PromiseReturns a promise.

ExamplesDirect link to Examples

await SF.collection.delete("cost-centers",{value : "it"})

aggregateDirect link to aggregate

Aggregation operations process data records and return computed results

ParametersDirect link to Parameters

NameTypeDescription
collectionstringCollection name in Softyflow.
aggregationarrayAggregation array.

ReturnsDirect link to Returns

TypeDescription
PromiseReturns a promise.

ExamplesDirect link to Examples

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.

cleanCollectionDirect link to cleanCollection

Remove All Documents from a Collection.

ParametersDirect link to Parameters

NameTypeDescription
collectionstringCollection name in Softyflow.

ReturnsDirect link to Returns

TypeDescription
PromiseReturns a promise.

ExamplesDirect link to Examples

await SF.collection.cleanCollection("cost-centers")

bulkWriteDirect link to bulkWrite

Is a function that performs multiple write operations (insert, update, delete) in a single batch on a specified MongoDB collection.

ParametersDirect link to Parameters

NameTypeDescription
colstringThe name of the collection (without suffix).
bulkOpsArrayAn array of bulk write operations (insertOne, updateOne, deleteOne, etc.).

ReturnsDirect link to Returns

TypeDescription
PromiseReturns a Promise that resolves once all bulk operations are complete.

ExamplesDirect link to Examples

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);
// returns: Promise resolved when all operations are completed

3 - UsersDirect link to 3 - Users


getUsersinGroupDirect link to getUsersinGroup

Get all users in a given group

ParametersDirect link to Parameters

NameTypeDescription
groupstringGroup ID.

ReturnsDirect link to Returns

TypeDescription
PromiseReturns a promise.

ExamplesDirect link to Examples

await SF.user.getUsersinGroup("6042551d231e8c8ade19bc09")

getUsersInGroupListDirect link to getUsersInGroupList

get the users who exist in certain groups.

ParametersDirect link to Parameters

NameTypeDescription
groupsstring[]Array of groupID.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.user.getUsersInGroupList(["6042551d231e8c8ade19bc09","6040e3679c81cf1b60b698f4"])

getGroupByIdDirect link to getGroupById

Is a function that retrieves a group document from the "groups" collection by its unique ID.

ParametersDirect link to Parameters

NameTypeDescription
idstringThe ID of the group to be retrieved.

ReturnsDirect link to Returns

TypeDescription
`Promise<objectnull>`

ExamplesDirect link to Examples

let group = await SF.utils.getGroupById("60c72b2f9f1b2c3c8f3b8b0b");
// returns: { _id: ObjectId("60c72b2f9f1b2c3c8f3b8b0b"), name: 'Admin', members: [...] }

let group = await SF.utils.getGroupById("60c72b2f9f1b2c3c8f3b8b0c");
// returns: null (if group with this ID doesn't exist)

getUserByIdDirect link to getUserById

Get user information using his id.

ParametersDirect link to Parameters

NameTypeDescription
idstringUser ID.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.user.getUserById("6042551d231e8c8ade19bc09")

getUserByMailDirect link to getUserByMail

Get user information using his email.

ParametersDirect link to Parameters

NameTypeDescription
emailstringUser email.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.user.getUserByMail("jean.dupont@example.com")

updateUserByIdDirect link to updateUserById

Update user information using his ID.

ParametersDirect link to Parameters

NameTypeDescription
idstringUser ID.
dataobjectJSON object of values to update.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.user.updateUserById("6042551d231e8c8ade19bc09",{firstName : "test"})

updateUsersEachDirect link to updateUsersEach

Update a list of users individualy : to each user their own payload.

ParametersDirect link to Parameters

NameTypeDescription
ArrayArrayArray of objects, each containing a user ID and a payload.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.user.updateUsersEach([{ _id: "6042551d231e8c8ade19bc09", payload: { firstName: 'firstUser' } }, { _id: "6042551d231e8c8ade19bc10", payload: { firstName: 'secondUser' } }])

updateUserMetadataByIdDirect link to updateUserMetadataById

Update user metadata using his ID.

ParametersDirect link to Parameters

NameTypeDescription
idstringUser ID.
fieldobjectJSON object of metadata to update.
valueobjectJSON object of values to be updated.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.user.updateUserMetadataById("6042551d231e8c8ade19bc09", "Manager",  "test")

getUsersDirect link to getUsers

Get users informations.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.user.getUsers()

getUserMetadataDirect link to getUserMetadata

Get user metadata using his ID.

ParametersDirect link to Parameters

NameTypeDescription
idstringUser ID.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.user.getUserMetadata("6042551d231e8c8ade19bc09")

addUserToGroupDirect link to addUserToGroup

Add user to a groupe using user ID & group ID.

ParametersDirect link to Parameters

NameTypeDescription
userIdstringUser ID.
groupidstringGroup ID.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.user.addUserToGroup("6042551d231e8c8ade19bc09", "62c2b6f74d16c2a2c19dcdb7")

removeUserfromGroupDirect link to removeUserfromGroup

Remove user from group using user ID & group ID.

ParametersDirect link to Parameters

NameTypeDescription
userIdstringUser ID.
groupidstringGroup ID.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.user.removeUserfromGroup("6042551d231e8c8ade19bc09", "62c2b6f74d16c2a2c19dcdb7")

createUserDirect link to createUser

Allow to create new user.

ParametersDirect link to Parameters

NameTypeDescription
dataobjectJSON content user data

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

DataDirect link to Data

This is the allowed user data:

fieldDescription
emailRequired and Unique. The user email (string)
lastNameRequired. The user last name (string)
firstNameRequired. The user first name (string)
groupRequired. The user production groups ids (array)
group_testOptional. The user test groups ids (array)
group_uatOptional. The user UAT groups ids (array)
metadata_testOptional. The user test metadata (json)
metadata_uatOptional. The user UAT metadata (json)
metadata_prodOptional. The user production metadata (json)
ideAccessRequired. IDE access right (boolean)
blockedOptional. User blocking (boolean)
sendMailOptional. Send email notification to the user (boolean)
getPasswordOptional. Get the generated password in response (boolean)

ExamplesDirect link to Examples

 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);

4 - FilesDirect link to 4 - Files


The File class manages files stored in MongoDB's GridFS system, providing methods to upload, retrieve, delete, and generate PDFs from EJS templates.

getFileContentByIdDirect link to getFileContentById

Retrieve the text content of a file by its ID.

ParametersDirect link to Parameters

NameTypeDescription
idstringFile ObjectId
encodingstringEncoding to use (default: 'utf8')

ReturnsDirect link to Returns

TypeDescription
Promise<object>File metadata with content field

ExampleDirect link to Example

let result = await SF.file.getFileContentById("64bfa28cfabc123...", "utf8");
console.log(result.content);

getFileBufferByIdDirect link to getFileBufferById

Retrieve the binary content of a file as a Buffer.

ParametersDirect link to Parameters

NameTypeDescription
idstringFile ObjectId

ReturnsDirect link to Returns

TypeDescription
Promise<Buffer>File data as Buffer

ExampleDirect link to Example

let buffer = await SF.file.getFileBufferById("64bfa28cfabc123...");

generatePDFFromTemplateDirect link to generatePDFFromTemplate

Generate a PDF from a stored EJS template file and save it back to GridFS.

ParametersDirect link to Parameters

NameTypeDescription
dump_varanyNot used
fidstringTemplate file ID
contextobjectPDF generation context

ReturnsDirect link to Returns

TypeDescription
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.

ExampleDirect link to Example

await SF.file.generatePDFFromTemplate(null, 'templateId', {
  variables: { name: "John" },
  SF_pdfName: "user-report.pdf"
});

createFileFromBufferDirect link to createFileFromBuffer

Create and upload a file from a Buffer.

ParametersDirect link to Parameters

NameTypeDescription
fileMetadataobjectMetadata (filename, contentType, etc.)
bufferContentBufferBinary content of the file

ReturnsDirect link to Returns

TypeDescription
Promise<object>Metadata of saved file

ExampleDirect link to Example

await SF.file.createFileFromBuffer({ filename: "doc.txt", contentType: "text/plain" }, Buffer.from("Hello"));

fillTemplateDirect link to fillTemplate

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.

ParametersDirect link to Parameters

NameTypeDescription
idstringTemplate file ObjectId
dataobjectJSON data to inject into the template

ReturnsDirect link to Returns

TypeDescription
Promise<string>File ID of the newly created filled document

Template CreationDirect link to Template Creation

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.

ExampleDirect link to Example

// Assuming you have a template file with placeholders like:
// Invoice for: {d.customerName}
// Amount: {d.amount}
// Date: {d.date}

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 }
  ]
};

// Fill the template
let filledDocumentId = await SF.file.fillTemplate("64bfa28cfabc123...", data);
console.log("Filled document ID:", filledDocumentId);

Advanced Template FeaturesDirect link to Advanced Template Features

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.

deleteFileByIdDirect link to deleteFileById

Is a function that deletes a file from the database by its unique ID.

ParametersDirect link to Parameters

NameTypeDescription
idstringThe ID of the file to be deleted.

ReturnsDirect link to Returns

TypeDescription
Promise<object>Resolves to an object indicating deletion status: { deleted: 1 } if successful, { deleted: 0 } if failed.

ExamplesDirect link to Examples

let result = await SF.file.deleteFileById("60c72b2f9f1b2c3c8f3b8b0b");
// returns: { deleted: 1 } (if file was deleted)

let result = await SF.file.deleteFileById("60c72b2f9f1b2c3c8f3b8b0c");
// returns: { deleted: 0 } (if there was an error or file not found)

5 - SqlDirect link to 5 - Sql


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".

insertOneDirect link to insertOne

Insert a row into your SQL Table

ParametersDirect link to Parameters

NameTypeDescription
idstringDatabase ID.
namestringTable name.
dataobjectData to insert into database.

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

await SF.sql.insertOne("610c0343f6ebc7ddcb49cc3b", "client", {
    code: 'MMA',
    codepostal: 225
})

insertManyDirect link to insertMany

Insert an array of rows into your SQL Table

ParametersDirect link to Parameters

NameTypeDescription
idstringDatabase ID.
namestringTable name.
dataarrayData to insert into database.

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

await SF.sql.insertMany("610c0343f6ebc7ddcb49cc3b", "client", [{
    code: 'MMA',
    codepostal: 225
}])

findOneDirect link to findOne

Find data in your SQL table.

ParametersDirect link to Parameters

NameTypeDescription
idstringDatabase ID.
namestringTable name.
datastringCriteria to query database.

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

await SF.sql.findOne("610c0343f6ebc7ddcb49cc3b", "client", "code='MGMT'")

findDirect link to find

Find all rows in your SQL table that match a certain criteria.

ParametersDirect link to Parameters

NameTypeDescription
idstringDatabase ID.
namestringTable name.
optionsobjectquery: criteria (string or object); optional sortby (column); with sortby, limit and page page the result (without sortby, they are ignored).

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

await SF.sql.find("610c0343f6ebc7ddcb49cc3b", "client", { query: "code='MGMT'" })

// the first 20 rows, sorted by name (descending order)
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.

updateDirect link to update

Update data in your database.

ParametersDirect link to Parameters

NameTypeDescription
idstringDatabase ID.
namestringTable name.
datastring or objectCriteria selecting the rows to update (required on a SQL database, see above).
newDataobjectUpdated data.

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

await SF.sql.update("610c0343f6ebc7ddcb49cc3b", "client", "code='MDMS'", {
    code: 'CLEA'
})

// Same selection written as an object
await SF.sql.update("610c0343f6ebc7ddcb49cc3b", "client", { code: 'MDMS' }, { code: 'CLEA' })

// Every row, on purpose
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.

deleteDirect link to delete

Delete rows from your database.

ParametersDirect link to Parameters

NameTypeDescription
idstringDatabase ID.
namestringTable name.
datastring or objectCriteria selecting the rows to delete (required on a SQL database, see above).

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

 await SF.sql.delete("610c0343f6ebc7ddcb49cc3b", "client", "code='CLEA'")

 // Empty the table, on purpose
 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.

countDirect link to count

count rows in your database.

ParametersDirect link to Parameters

NameTypeDescription
idstringDatabase ID.
namestringTable name.
datastringCriteria to query database.

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

 await SF.sql.count("610c0343f6ebc7ddcb49cc3b", "client", "code='CLEA'")

executeDirect link to execute

Execute custom/complex statements on your database.

ParametersDirect link to Parameters

NameTypeDescription
idstringDatabase ID.
querystringSQL statement.

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

await SF.sql.execute('610c0343f6ebc7ddcb49cc3b', "DELETE FROM client WHERE code='KL'")

6 - InstanceDirect link to 6 - Instance


launchProcessDirect link to launchProcess

Initiate an existing process.

ParametersDirect link to Parameters

NameTypeDescription
processIdstringProcess ID.
modelsobjectOptional. Variables of the new instance.
optionsobjectOptional. { 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.

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

await SF.instance.launchProcess('610c0343f6ebc7ddcb49cc3b')

// In an API: start the process on behalf of the caller
await SF.instance.launchProcess('610c0343f6ebc7ddcb49cc3b', { amount: 120 }, { onBehalfOf: SF_initiator })

findOneDirect link to findOne

Find one instance that satisfies the specified query criteria.

ParametersDirect link to Parameters

NameTypeDescription
queryobjectJSON object of criteria to match the instance.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

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.

findDirect link to find

Find all instances that satisfy the specified query criteria.

ParametersDirect link to Parameters

NameTypeDescription
queryobjectJSON object of criteria to match instances.

ReturnsDirect link to Returns

TypeDescription
CursorA MongoDB cursor, not a list: call .toArray() on it to get the instances.

ExamplesDirect link to Examples

const instances = await SF.instance.find({ status: 'Running' }).toArray()

pendingTaskDirect link to pendingTask

Get Instance latest Pending Task

ParametersDirect link to Parameters

NameTypeDescription
instanceIdstringInstance ID.

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

await SF.instance.pendingTask('610c0343f6ebc7ddcb49cc3b')

getMeasuresDirect link to getMeasures

Get Instance Measures

ParametersDirect link to Parameters

NameTypeDescription
instanceIdstringInstance ID.

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

await SF.instance.getMeasures('610c0343f6ebc7ddcb49cc3b')

validateTaskDirect link to validateTask

Validate Task.

ParametersDirect link to Parameters

NameTypeDescription
taskIdstringTask ID.
variablesobjectJSON of variables.

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

let variables = {
  "variable1": "value1",
  "variable2": 1,
  "variable3": true
}
await SF.instance.validateTask('610c0343f6ebc7ddcb49cc3b',variables)

updateVariablesByIdDirect link to updateVariablesById

Update variables using instance ID.

ParametersDirect link to Parameters

NameTypeDescription
IdstringInstance ID.
dataobjectJSON of variables data.

ReturnsDirect link to Returns

TypeDescription
objectReturn object

ExamplesDirect link to Examples

let data = {
  "variable1": "value1",
  "variable2": 1,
  "variable3": true
}
await SF.instance.updateVariablesById('610c0343f6ebc7ddcb49cc3b',data)

attachChildInstanceDirect link to attachChildInstance

Is a function that links a child instance to a father instance in the "instances" collection, based on a specific activity step.

ParametersDirect link to Parameters

NameTypeDescription
fatherIdstringThe ID of the father instance.
childIdstringThe ID of the child instance to be attached.
stepIdstringThe step ID representing the activity in the father instance.

ReturnsDirect link to Returns

TypeDescription
Promise<object>Resolves to { done: true } if the attachment is successful.

ExamplesDirect link to Examples

let result = await SF.utils.attachChildInstance(
  "661e9d8a1a2b2f7f8d3c4e1f",
  "661e9d9b2b5e2f8f8d3c5f0a",
  "step123"
);
// returns: { done: true }

getVariablesByIdDirect link to getVariablesById

Is a function that retrieves an instance document by its ID, with an optional projection to select specific fields.

ParametersDirect link to Parameters

NameTypeDescription
instanceIdstringThe ID of the instance to retrieve.
projectionobject(Optional) MongoDB projection to specify which fields to return.

ReturnsDirect link to Returns

TypeDescription
Promise<object \| null>Resolves to the instance document if found, or null if not found.

ExamplesDirect link to Examples

let instance = await SF.utils.getVariablesById("661e9d8a1a2b2f7f8d3c4e1f");
// returns: Full instance document

let instance = await SF.utils.getVariablesById("661e9d8a1a2b2f7f8d3c4e1f", { variables: 1 });
// returns: { variables: {...} }

deleteInstanceByIdDirect link to deleteInstanceById

Deletes an instance by its ID, and also removes all related histories, tasks, and instancelights associated with that instance.

ParametersDirect link to Parameters

NameTypeDescription
idstringThe ID of the instance to be deleted.

ReturnsDirect link to Returns

TypeDescription
Promise<object>Resolves to { done: true } if the deletion is successful.

ExamplesDirect link to Examples

let result = await SF.instance.deleteInstanceById("661e9d8a1a2b2f7f8d3c4e1f");
// returns: { done: true }

deleteManyInstancesDirect link to deleteManyInstances

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.

ParametersDirect link to Parameters

NameTypeDescription
processIdstringThe ID of the process whose instances should be deleted.
queryobjectAdditional query parameters to filter which instances to delete.

ReturnsDirect link to Returns

TypeDescription
Promise<object>Resolves to { done: true } if successful.

ExamplesDirect link to Examples

let result = await SF.instance.deleteManyInstances("661e9d8a1a2b2f7f8d3c4e1f", { status: "End" });
await SF.instance.deleteManyInstances("661e9d8a1a2b2f7f8d3c4e1f", { createdAt: { $lt: SF.utils.moment().subtract(5, 'days') } })
// returns: { done: true }

deleteManyInstancesWithTasksAndHistoriesDirect link to deleteManyInstancesWithTasksAndHistories

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.

ParametersDirect link to Parameters

NameTypeDescription
processIdstringThe ID of the process whose instances should be deleted.
queryobjectAdditional query parameters to filter which instances to delete.

ReturnsDirect link to Returns

TypeDescription
Promise<object>Resolves to { done: true } if successful.

ExamplesDirect link to Examples

// Delete all completed instances with full cleanup
let result = await SF.instance.deleteManyInstancesWithTasksAndHistories(
  "661e9d8a1a2b2f7f8d3c4e1f", 
  { status: "End" }
);
// returns: { done: true }

// Delete all instances older than a certain date
let result = await SF.instance.deleteManyInstancesWithTasksAndHistories(
  "661e9d8a1a2b2f7f8d3c4e1f", 
  { createdAt: { $lt: new Date('2024-01-01') } }
);
// returns: { done: true }

updateInstanceVariablesDirect link to updateInstanceVariables

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.

ParametersDirect link to Parameters

NameTypeDescription
idstringThe ID of the instance to update.
dataobjectKey-value pairs of variables to update inside the instance.

ReturnsDirect link to Returns

TypeDescription
Promise<object>Resolves to { done: true } if the update succeeds.

ExamplesDirect link to Examples

let result = await SF.instance.updateInstanceVariables("661e9d8a1a2b2f7f8d3c4e1f", {
  amount: 1500,
  dueDate: "2025-05-30"
});
// returns: { done: true }

7 - SoftyTableDirect link to 7 - SoftyTable


The SoftyTable SDK provides methods to interact with SoftyTable resources, allowing you to perform CRUD operations, execute queries, and manage table data.

UsageDirect link to Usage

The SoftyTable is available as a direct instance on the SF object. All methods take the table ID as the first parameter:

// Access methods directly from SF.softyTable
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).

Behaviour since 8.6Direct link to Behaviour since 8.6

  • 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.

listDirect link to list

Retrieve rows from a SoftyTable with optional filtering, sorting, and pagination.

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
criteriaobjectQuery criteria with optional where, attributes, include, group, etc. (default: {})
limitnumberMaximum number of rows to return (default: 100)
pagenumberPage number for pagination (default: 0)
sortbystringField name to sort by (default: 'createdAt')
directionnumberSort direction: 1 for ASC, -1 for DESC (default: 1)
orderarrayCustom order array, e.g., [['field', 'ASC']] (default: null)

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to an array of table rows

ExamplesDirect link to Examples

// List all rows
let rows = await SF.softyTable.list('610c0343f6ebc7ddcb49cc3b');

// List with filters
let activeRows = await SF.softyTable.list(
  '610c0343f6ebc7ddcb49cc3b',
  { where: { status: 'active' } }, 
  50, 
  0, 
  'createdAt', 
  -1
);

// List with complex criteria
let rows = await SF.softyTable.list(
  '610c0343f6ebc7ddcb49cc3b',
  {
    where: { age: { $gte: 18 } },
    attributes: ['name', 'email', 'age']
  }, 
  20, 
  0
);

countDirect link to count

Count the number of rows in a SoftyTable with optional filtering.

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
criteriaobjectQuery criteria with optional where clause (default: {})

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to an object with count property

ExamplesDirect link to Examples

// Count all rows
let result = await SF.softyTable.count('610c0343f6ebc7ddcb49cc3b');
// returns: { count: 150 }

// Count with filter
let result = await SF.softyTable.count(
  '610c0343f6ebc7ddcb49cc3b',
  { where: { status: 'active' } }
);
// returns: { count: 75 }

createDirect link to create

Create a single row in a SoftyTable.

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
dataobjectThe data object to insert as a row

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to the created row data

ExamplesDirect link to Examples

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).

createManyDirect link to createMany

Create multiple rows in a SoftyTable at once.

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
dataarrayArray of data objects to insert

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to an array of created rows

ExamplesDirect link to Examples

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 }
  ]
);

retrieveDirect link to retrieve

Retrieve a single row from a SoftyTable by its ID.

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
rowIdstringThe ID of the row

ReturnsDirect link to Returns

TypeDescription
PromiseResolves 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>

ExamplesDirect link to Examples

let row = await SF.softyTable.retrieve('610c0343f6ebc7ddcb49cc3b', '12345');
// row.client_id_record → the parent row (all its columns)
// row.tags → [3, 7] (ids of the linked rows of the many-to-many column "tags")

updateDirect link to update

Update a single row in a SoftyTable by its ID.

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
rowIdstringThe ID of the row to update
dataobjectThe fields and values to update

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to the updated row

ExamplesDirect link to Examples

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).

updateManyDirect link to updateMany

Update multiple rows in a SoftyTable that match specific criteria.

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
criteriaobjectFilter on the columns, written directly (no where key), for example { status: 'pending' }. Required: an empty criteria is refused
dataobjectThe fields and values to update

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to update operation result

ExamplesDirect link to Examples

// Update all rows where status is 'pending'
let result = await SF.softyTable.updateMany(
  '610c0343f6ebc7ddcb49cc3b',
  { status: 'pending' },
  { status: 'active', processedAt: new Date() }
);

// Every row, on purpose: an explicit criteria
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.

deleteDirect link to delete

Delete a single row from a SoftyTable by its ID.

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
rowIdstringThe ID of the row

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to deletion result

ExamplesDirect link to Examples

await SF.softyTable.delete('610c0343f6ebc7ddcb49cc3b', '12345');

deleteManyDirect link to deleteMany

Delete multiple rows from a SoftyTable that match specific criteria.

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
criteriaobjectFilter on the columns, written directly (no where key). Required: an empty criteria is refused

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to deletion result

ExamplesDirect link to Examples

// Delete all inactive rows
await SF.softyTable.deleteMany(
  '610c0343f6ebc7ddcb49cc3b',
  { status: 'inactive' }
);

// Delete rows older than a certain date
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.

clearDirect link to clear

Clear all rows from a SoftyTable (delete all data).

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to deletion result

ExamplesDirect link to Examples

// Remove all rows from the table
await SF.softyTable.clear('610c0343f6ebc7ddcb49cc3b');

getOptionsDirect link to getOptions

Retrieve options for select fields in a SoftyTable.

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
optionsIdstringThe ID of the options field

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to array of options

ExamplesDirect link to Examples

let options = await SF.softyTable.getOptions(
  '610c0343f6ebc7ddcb49cc3b',
  'status_field'
);
// returns: [{ label: 'Active', value: 'active' }, { label: 'Inactive', value: 'inactive' }]

joinTableListDirect link to joinTableList

List rows from a joined table (many-to-many relationship).

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
joinTableIdstringThe ID of the join table field
criteriaobjectQuery criteria with optional where clause (default: {})
limitnumberMaximum number of rows to return (default: 100)
pagenumberPage number for pagination (default: 0)
sortbystringField name to sort by (default: 'createdAt')
directionnumberSort direction: 1 for ASC, -1 for DESC (default: 1)
orderarrayCustom order array (default: null)

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to an array of joined rows

ExamplesDirect link to Examples

// List all related items
let relatedItems = await SF.softyTable.joinTableList(
  '610c0343f6ebc7ddcb49cc3b',
  'related_products'
);

// List with filters and pagination
let items = await SF.softyTable.joinTableList(
  '610c0343f6ebc7ddcb49cc3b',
  'related_products',
  { where: { category: 'electronics' } },
  20,
  0,
  'price',
  -1
);

joinTableCountDirect link to joinTableCount

Count rows from a joined table (many-to-many relationship).

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
joinTableIdstringThe ID of the join table field
criteriaobjectQuery criteria with optional where clause (default: {})

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to an object with count

ExamplesDirect link to Examples

let result = await SF.softyTable.joinTableCount(
  '610c0343f6ebc7ddcb49cc3b',
  'related_products'
);
// returns: { count: 45 }

let result = await SF.softyTable.joinTableCount(
  '610c0343f6ebc7ddcb49cc3b',
  'related_products',
  { where: { category: 'electronics' } }
);
// returns: { count: 12 }

executeDirect link to execute

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.

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
querystringThe SQL query to execute
optionsobjectQuery options with replacements and type (default: {})

Options ObjectDirect link to Options Object

FieldTypeDescription
replacementsobjectValues to replace in parameterized queries
typestringQuery type: 'SELECT', 'INSERT', 'UPDATE', 'DELETE', 'RAW', 'SHOWTABLES'

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to the query results

ExamplesDirect link to Examples

// Execute a SELECT query
let results = await SF.softyTable.execute(
  '610c0343f6ebc7ddcb49cc3b',
  'SELECT * FROM @table(my_table) WHERE status = :status',
  {
    replacements: { status: 'active' },
    type: 'SELECT'
  }
);

// Execute a custom query
let results = await SF.softyTable.execute(
  '610c0343f6ebc7ddcb49cc3b',
  `UPDATE @table(my_table) SET status = 'processed' WHERE "createdAt" < NOW() - INTERVAL '30 days'`,
  { type: 'UPDATE' }
);

migrateDirect link to migrate

Migrate rows in a SoftyTable (for data migration operations).

ParametersDirect link to Parameters

NameTypeDescription
tableIdstringThe ID of the SoftyTable
migrationDataobjectMigration configuration data

ReturnsDirect link to Returns

TypeDescription
PromiseResolves to migration result

ExamplesDirect link to Examples

let result = await SF.softyTable.migrate(
  '610c0343f6ebc7ddcb49cc3b',
  {
    // Migration configuration
  }
);

8 - TaskDirect link to 8 - Task


The Task SDK provides methods to interact with task resources, allowing you to query, update, save, and delete tasks.

findOneDirect link to findOne

Find one task that satisfies the specified query criteria.

ParametersDirect link to Parameters

NameTypeDescription
queryobjectJSON object of criteria to match the task.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

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.

findDirect link to find

Find all tasks that satisfy the specified query criteria.

ParametersDirect link to Parameters

NameTypeDescription
queryobjectJSON object of criteria to match tasks.

ReturnsDirect link to Returns

TypeDescription
CursorA MongoDB cursor, not a list: call .toArray() on it to get the tasks.

ExamplesDirect link to Examples

const tasks = await SF.task.find({ status: 'Running' }).toArray()

deleteTaskByIdDirect link to deleteTaskById

Delete a task by its ID.

ParametersDirect link to Parameters

NameTypeDescription
idstringTask ID.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.task.deleteTaskById('610c0343f6ebc7ddcb49cc3b')

deleteManyDirect link to deleteMany

Delete multiple tasks that match the specified query criteria.

ParametersDirect link to Parameters

NameTypeDescription
queryobjectJSON object of criteria to match tasks.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

// Delete all tasks with status 'End' (completed tasks)
await SF.task.deleteMany({ status: 'End' })

deleteHistoryByTaskIdDirect link to deleteHistoryByTaskId

Delete all history records associated with a specific task.

ParametersDirect link to Parameters

NameTypeDescription
taskIdstringTask ID.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.task.deleteHistoryByTaskId('610c0343f6ebc7ddcb49cc3b')

deleteHistoryByInstanceIdDirect link to deleteHistoryByInstanceId

Delete all history records associated with a specific instance.

ParametersDirect link to Parameters

NameTypeDescription
instanceIdstringInstance ID.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.task.deleteHistoryByInstanceId('610c0343f6ebc7ddcb49cc3b')

deleteHistoryDirect link to deleteHistory

Delete history records that match the specified query criteria.

ParametersDirect link to Parameters

NameTypeDescription
queryobjectJSON object of criteria to match histories.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

// Delete all history records for a specific action
await SF.task.deleteHistory({ action: 'task_completed' })

// Delete history records older than a certain date
await SF.task.deleteHistory({ createdAt: { $lt: new Date('2024-01-01') } })

saveTaskDirect link to saveTask

Save a task with updated data.

ParametersDirect link to Parameters

NameTypeDescription
taskIdstringTask ID.
bodyobjectVariables to save as a draft on the task (stored in savedVariables, the task stays open).

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

await SF.task.saveTask('610c0343f6ebc7ddcb49cc3b', {
  comment: 'To be reviewed on Monday'
})

updateTaskDirect link to updateTask

Update a task by its ID.

ParametersDirect link to Parameters

NameTypeDescription
idstringTask ID.
dataobjectJSON object of values to update.

ReturnsDirect link to Returns

TypeDescription
PromiseReturn promise

ExamplesDirect link to Examples

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.

replaceUser, replaceRole, deleteUser, deleteRoleDirect link to replaceUser, replaceRole, deleteUser, deleteRole

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 })
MethodWhat changes on each task
replaceUserfrom is replaced by to in the assignees and the observers.
replaceRolethe role from is replaced by the role to.
deleteUserfrom is removed from the assignees and the observers.
deleteRolethe role from is removed.

ParametersDirect link to Parameters

One object:

NameTypeDescription
fromstringRequired. The user's e-mail (replaceUser, deleteUser) or the role ID (replaceRole, deleteRole). E-mails match whatever their case.
tostringRequired for replaceUser and replaceRole. The new user's e-mail or the new role ID. It must exist.
processesstring[]Required. IDs of the processes whose open tasks are changed.
queryobjectOptional. 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).

ReturnsDirect link to Returns

TypeDescription
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.

ExamplesDirect link to Examples

// Ali leaves: his open tasks of two processes go to Sara
await SF.task.replaceUser({
  from: 'ali@acme.com',
  to: 'sara@acme.com',
  processes: ['6aeca4b1f6ebc7ddcb49cc3b', '6aeca4c2f6ebc7ddcb49cc3b']
})

// Only the tasks created since November with an amount above 1 000
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'] })
// result.skipped: tasks that only this role could see