Skip to main content

Process modeler SDK

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.

1 - Utils​


The utils object has the methods that will allow you 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.

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

Returns​

TypeDescription
PromiseA Promise that resolves to the generated ID.

Examples​

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

shellExecLocal​

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

Parameters​

NameTypeDescription
cmdstringThe shell command to be executed.

Returns​

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

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' }

shellExecRemote​

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

Parameters​

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

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.

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 }

axios​

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

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 - Collection​


insertMany​

Allow to insert an array of json in to a collection

Parameters​

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

Returns​

TypeDescription
PromiseA Promise indicating the result of the insert operation.

Examples​

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

insertOne​

Allow to insert a json in to a collection

Parameters​

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

Returns​

TypeDescription
PromiseA Promise indicating the result of the insert operation.

Examples​

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

findOne​

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

Parameters​

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

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

find​

Returns all the documents that satisfies the specified query criteria .

Parameters​

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

Returns​

TypeDescription
PromiseA Promise indicating the result of the find operation.

Examples​

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

updateOne​

update the first document that satisfies the specified query criteria .

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.

Returns​

TypeDescription
PromiseA Promise indicating the result of the update operation.

Examples​

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

update​

update all the documents that satisfies the specified query criteria .

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.

Returns​

TypeDescription
PromiseReturns a promise.

Examples​

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

count​

Returns the count of documents in the collection.

Parameters​

NameTypeDescription
collectionstringCollection name in Softyflow.

Returns​

TypeDescription
PromiseReturns a promise.

Examples​

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

deleteOne​

Allow to delete a document from collection.

Parameters​

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

Returns​

TypeDescription
PromiseReturns a promise.

Examples​

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

delete​

Allow to delete multiple documents from collection.

Parameters​

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

Returns​

TypeDescription
PromiseReturns a promise.

Examples​

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

aggregate​

Aggregation operations process data records and return computed results

Parameters​

NameTypeDescription
collectionstringCollection name in Softyflow.
aggregationarrayAggregation array.

Returns​

TypeDescription
PromiseReturns a promise.

Examples​

let aggregation = [
{
"$match": { "type": "type1" }
},
{
"$project" : {
"_id": 1,
"name": 1
}
}
]
await SF.collection.aggregate("cost-centers",[aggregation]);

cleanCollection​

Remove All Documents from a Collection.

Parameters​

NameTypeDescription
collectionstringCollection name in Softyflow.

Returns​

TypeDescription
PromiseReturns a promise.

Examples​

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

bulkWrite​

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

Parameters​

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

Returns​

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

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 - Users​


getUsersinGroup​

Get all users in a given group

Parameters​

NameTypeDescription
groupstringGroup ID.

Returns​

TypeDescription
PromiseReturns a promise.

Examples​

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

getUsersInGroupList​

get the users who exist in certain groups.

Parameters​

NameTypeDescription
groupsstring[]Array of groupID.

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

getGroupById​

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

Parameters​

NameTypeDescription
idstringThe ID of the group to be retrieved.

Returns​

TypeDescription
`Promise<objectnull>`

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)

getUserById​

Get user information using his id.

Parameters​

NameTypeDescription
idstringUser ID.

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

getUserByMail​

Get user information using his email.

Parameters​

NameTypeDescription
emailstringUser email.

Returns​

TypeDescription
PromiseReturn promise

Examples​

await SF.user.getUserByMail("test@softyflow.com")

updateUserById​

Update user information using his ID.

Parameters​

NameTypeDescription
idstringUser ID.
dataobjectJSON object of values to update.

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

updateUsersEach​

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

Parameters​

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

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

updateUserMetadataById​

Update user metadata using his ID.

Parameters​

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

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

getUsers​

Get users informations.

Returns​

TypeDescription
PromiseReturn promise

Examples​

await SF.user.getUsers()

getUserMetadata​

Get user metadata using his ID.

Parameters​

NameTypeDescription
idstringUser ID.

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

addUserToGroup​

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

Parameters​

NameTypeDescription
userIdstringUser ID.
groupidstringGroup ID.

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

removeUserfromGroup​

Remove user from group using user ID & group ID.

Parameters​

NameTypeDescription
userIdstringUser ID.
groupidstringGroup ID.

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

createUser​

Allow to create new user.

Parameters​

NameTypeDescription
dataobjectJSON content user data

Returns​

TypeDescription
PromiseReturn promise

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 groups ids (array)
metadataoptional. The user metadata (json)
ideAccessRequired. IDE access right (boolean)
blockedoptional. User blocking (boolean)

Examples​

let user = {
email: "email@softyflow.com",
lastName : "last name",
firstName: "first name",
group: [],
metadata: {},
ideAccess: true,
blocked: false
}
await SF.users.createUser(user);

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.

Usage​

const file = new File(gridfsBucket);

getFileContentById​

Retrieve the text content of a file by its ID.

Parameters​

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

Returns​

TypeDescription
Promise<object>File metadata with content field

Example​

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

getFileBufferById​

Retrieve the binary content of a file as a Buffer.

Parameters​

NameTypeDescription
idstringFile ObjectId

Returns​

TypeDescription
Promise<Buffer>File data as Buffer

Example​

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

generatePDFFromTemplate​

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

Parameters​

NameTypeDescription
dump_varanyNot used
fidstringTemplate file ID
contextobjectPDF generation context

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.

Example​

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

createFileFromBuffer​

Create and upload a file from a Buffer.

Parameters​

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

Returns​

TypeDescription
Promise<object>Metadata of saved file

Example​

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

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.

Parameters​

NameTypeDescription
idstringTemplate file ObjectId
dataobjectJSON data to inject into the template

Returns​

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

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.

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

deleteFileById​

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

Parameters​

NameTypeDescription
idstringThe ID of the file to be deleted.

Returns​

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

Examples​

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

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

5 - Sql​


insertOne​

Insert a row into your SQL Table

Parameters​

NameTypeDescription
idstringDatabase ID.
dataobjectData to insert into database.

Returns​

TypeDescription
objectReturn object

Examples​

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

insertMany​

Insert an array of rows into your SQL Table

Parameters​

NameTypeDescription
idstringDatabase ID.
dataarrayData to insert into database.

Returns​

TypeDescription
objectReturn object

Examples​

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

findOne​

Find data in your SQL table.

Parameters​

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

Returns​

TypeDescription
objectReturn object

Examples​

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

find​

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

Parameters​

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

Returns​

TypeDescription
objectReturn object

Examples​

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

update​

Update data in your database.

Parameters​

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

Returns​

TypeDescription
objectReturn object

Examples​

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

delete​

Delete rows from your database.

Parameters​

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

Returns​

TypeDescription
objectReturn object

Examples​

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

count​

count rows in your database.

Parameters​

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

Returns​

TypeDescription
objectReturn object

Examples​

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

execute​

Execute custom/complex statements on your database.

Parameters​

NameTypeDescription
idstringDatabase ID.
querystringSQL statement.

Returns​

TypeDescription
objectReturn object

Examples​

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

6 - Instance​


launchProcess​

Initiate an existing process.

Parameters​

NameTypeDescription
processIdstringProcess ID.

Returns​

TypeDescription
objectReturn object

Examples​

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

findOne​

Find one instance that satisfies the specified query criteria.

Parameters​

NameTypeDescription
queryobjectJSON object of criteria to match the instance.

Returns​

TypeDescription
PromiseReturn promise

Examples​

await SF.instance.findOne({ _id: ObjectId('610c0343f6ebc7ddcb49cc3b') })

find​

Find all instances that satisfy the specified query criteria.

Parameters​

NameTypeDescription
queryobjectJSON object of criteria to match instances.

Returns​

TypeDescription
PromiseReturn promise

Examples​

await SF.instance.find({ status: 'running' })

pendingTask​

Get Instance latest Pending Task

Parameters​

NameTypeDescription
instanceIdstringInstance ID.

Returns​

TypeDescription
objectReturn object

Examples​

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

getMeasures​

Get Instance Measures

Parameters​

NameTypeDescription
instanceIdstringInstance ID.

Returns​

TypeDescription
objectReturn object

Examples​

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

validateTask​

Validate Task.

Parameters​

NameTypeDescription
taskIdstringTask ID.
variablesobjectJSON of variables.

Returns​

TypeDescription
objectReturn object

Examples​

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

updateVariablesById​

Update variables using instance ID.

Parameters​

NameTypeDescription
IdstringInstance ID.
dataobjectJSON of variables data.

Returns​

TypeDescription
objectReturn object

Examples​

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

attachChildInstance​

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

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.

Returns​

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

Examples​

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

getVariablesById​

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

Parameters​

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

Returns​

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

Examples​

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

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

deleteInstanceById​

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

Parameters​

NameTypeDescription
idstringThe ID of the instance to be deleted.

Returns​

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

Examples​

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

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.

Parameters​

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

Returns​

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

Examples​

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

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.

Parameters​

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

Returns​

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

Examples​

// Delete all completed instances with full cleanup
let result = await SF.instance.deleteManyInstancesWithTasksAndHistories(
"661e9d8a1a2b2f7f8d3c4e1f",
{ status: "completed" }
);
// 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 }

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.

Parameters​

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

Returns​

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

Examples​

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

7 - SoftyTable​


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

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

list​

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

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)

Returns​

TypeDescription
PromiseResolves to an array of table rows

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

count​

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

Parameters​

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

Returns​

TypeDescription
PromiseResolves to an object with count property

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 }

create​

Create a single row in a SoftyTable.

Parameters​

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

Returns​

TypeDescription
PromiseResolves to the created row data

Examples​

let newRow = await SF.softyTable.create(
'610c0343f6ebc7ddcb49cc3b',
{
name: 'John Doe',
email: 'john@example.com',
age: 30,
status: 'active'
}
);

createMany​

Create multiple rows in a SoftyTable at once.

Parameters​

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

Returns​

TypeDescription
PromiseResolves to an array of created rows

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

retrieve​

Retrieve a single row from a SoftyTable by its ID.

Parameters​

NameTypeDescription
tableIdstringThe ID of the SoftyTable
rowIdstringThe ID of the row

Returns​

TypeDescription
PromiseResolves to the row data

Examples​

let row = await SF.softyTable.retrieve('610c0343f6ebc7ddcb49cc3b', '12345');

update​

Update a single row in a SoftyTable by its ID.

Parameters​

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

Returns​

TypeDescription
PromiseResolves to the updated row

Examples​

let updated = await SF.softyTable.update(
'610c0343f6ebc7ddcb49cc3b',
'12345',
{
status: 'inactive',
updatedAt: new Date()
}
);

updateMany​

Update multiple rows in a SoftyTable that match specific criteria.

Parameters​

NameTypeDescription
tableIdstringThe ID of the SoftyTable
criteriaobjectQuery criteria with where clause
dataobjectThe fields and values to update

Returns​

TypeDescription
PromiseResolves to update operation result

Examples​

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

delete​

Delete a single row from a SoftyTable by its ID.

Parameters​

NameTypeDescription
tableIdstringThe ID of the SoftyTable
rowIdstringThe ID of the row

Returns​

TypeDescription
PromiseResolves to deletion result

Examples​

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

deleteMany​

Delete multiple rows from a SoftyTable that match specific criteria.

Parameters​

NameTypeDescription
tableIdstringThe ID of the SoftyTable
criteriaobjectQuery criteria with where clause

Returns​

TypeDescription
PromiseResolves to deletion result

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

clear​

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

Parameters​

NameTypeDescription
tableIdstringThe ID of the SoftyTable

Returns​

TypeDescription
PromiseResolves to deletion result

Examples​

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

getOptions​

Retrieve options for select fields in a SoftyTable.

Parameters​

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

Returns​

TypeDescription
PromiseResolves to array of options

Examples​

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

joinTableList​

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

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)

Returns​

TypeDescription
PromiseResolves to an array of joined rows

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

joinTableCount​

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

Parameters​

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

Returns​

TypeDescription
PromiseResolves to an object with count

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 }

execute​

Execute a custom SQL query on the SoftyTable.

Parameters​

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

Options Object​

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

Returns​

TypeDescription
PromiseResolves to the query results

Examples​

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

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

migrate​

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

Parameters​

NameTypeDescription
tableIdstringThe ID of the SoftyTable
migrationDataobjectMigration configuration data

Returns​

TypeDescription
PromiseResolves to migration result

Examples​

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

8 - Task​


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

findOne​

Find one task that satisfies the specified query criteria.

Parameters​

NameTypeDescription
queryobjectJSON object of criteria to match the task.

Returns​

TypeDescription
PromiseReturn promise

Examples​

await SF.task.findOne({ _id: ObjectId('610c0343f6ebc7ddcb49cc3b') })

find​

Find all tasks that satisfy the specified query criteria.

Parameters​

NameTypeDescription
queryobjectJSON object of criteria to match tasks.

Returns​

TypeDescription
PromiseReturn promise

Examples​

await SF.task.find({ status: 'pending' })

deleteTaskById​

Delete a task by its ID.

Parameters​

NameTypeDescription
idstringTask ID.

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

deleteMany​

Delete multiple tasks that match the specified query criteria.

Parameters​

NameTypeDescription
queryobjectJSON object of criteria to match tasks.

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

// Delete all tasks for a specific instance
await SF.task.deleteMany({ instanceId: ObjectId('610c0343f6ebc7ddcb49cc3b') })

deleteHistoryByTaskId​

Delete all history records associated with a specific task.

Parameters​

NameTypeDescription
taskIdstringTask ID.

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

deleteHistoryByInstanceId​

Delete all history records associated with a specific instance.

Parameters​

NameTypeDescription
instanceIdstringInstance ID.

Returns​

TypeDescription
PromiseReturn promise

Examples​

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

deleteHistory​

Delete history records that match the specified query criteria.

Parameters​

NameTypeDescription
queryobjectJSON object of criteria to match histories.

Returns​

TypeDescription
PromiseReturn promise

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') } })

saveTask​

Save a task with updated data.

Parameters​

NameTypeDescription
taskIdstringTask ID.
bodyobjectJSON object with task data.

Returns​

TypeDescription
PromiseReturn promise

Examples​

await SF.task.saveTask('610c0343f6ebc7ddcb49cc3b', {
status: 'in-progress',
assignee: 'user123'
})

updateTask​

Update a task by its ID.

Parameters​

NameTypeDescription
idstringTask ID.
dataobjectJSON object of values to update.

Returns​

TypeDescription
PromiseReturn promise

Examples​

await SF.task.updateTask('610c0343f6ebc7ddcb49cc3b', {
status: 'completed',
completedAt: new Date()
})