Process modeler SDK

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,
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#

Description#

Is a function that generate an incremental number based on given string

/**
* @param {string} name Unique name that will be used to generate the ID.
* @param {number} [padding] Padding of result with 000000.
*
* @return {promise} Return the 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

axios#

Description#

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#

Description#

Allow to insert an array of json in to a collection

/**
* @param {string} collection Collection name in softyflow.
* @param {array} data Array of data to be inserted in to the collection.
*
* @return {promise} Return promise
*/

Examples#

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

insertOne#

Description#

Allow to insert a json in to a collection

/**
* @param {string} collection Collection name in softyflow.
* @param {object} data Json of a value to be inserted in to the collection.
*
* @return {promise} Return promise
*/

Examples#

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

findOne#

Description#

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

/**
* @param {string} collection Collection name in softyflow.
* @param {object} query Json of a value to be matched in to the collection.
*
* @return {promise} Return promise
*/

Examples#

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

find#

Description#

Returns all the documents that satisfies the specified query criteria .

/**
* @param {string} collection Collection name in softyflow.
* @param {object} query Json of a value to be matched in to the collection.
*
* @return {promise} Return promise
*/

Examples#

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

updateOne#

Description#

update the first document that satisfies the specified query criteria .

/**
* @param {string} collection Collection name in softyflow.
* @param {object} query Json of a value to be matched in the collection.
* @param {object} body Json of a value to be updated in the collection.
*
* @return {promise} Return promise
*/

Examples#

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

update#

Description#

update all the documents that satisfies the specified query criteria .

/**
* @param {string} collection Collection name in softyflow.
* @param {object} query Json of a value to be matched in the collection.
* @param {object} body Json of a value to be updated in the collection.
*
* @return {promise} Return promise
*/

Examples#

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

count#

Description#

Returns the count of documents in the collection.

/**
* @param {string} collection Collection name in softyflow.
* @return {promise} Return promise
*/

Examples#

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

3 - Users#


getUsersinGroup#

Description#

Get all users in a given group

/**
* @param {string} group Group ID.
*
* @return {promise} Return promise
*/

Examples#

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

getUsersInGroupList#

Description#

get the users who exist in certain groups.

/**
* @param {string} groups Array of groupID.
*
* @return {promise} Return promise
*/

Examples#

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

getUserById#

Description#

Get user information using his id.

/**
* @param {string} id user ID.
*
* @return {promise} Return promise
*/

Examples#

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

getUserByMail#

Description#

Get user information using his email.

/**
* @param {string} email user EMAIL.
*
* @return {promise} Return promise
*/

Examples#

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

updateUserById#

Description#

Update user information using his ID.

/**
* @param {string} id user ID.
*
* @param {object} data Json of a value to be updated.
*
* @return {promise} Return promise
*/

Examples#

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

updateUsersEach#

Description#

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

/**
* @param {Array} Array of objects each containing a user id and a payload.
*
* @return {promise} Return promise
*/

Examples#

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

4 - Files#


getFileContentById#

Description#

Get the content of a file using his ID

/**
* @param {string} id File ID.
*
* @return {promise} Return promise
*/

Examples#

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

5 - Sql#


insertOne#

Description#

Insert a row into your SQL Table

/**
* @param {string} id Database id.
* @param {object} data data to insert into database.
*
* @return {object} Return object
*/

Examples#

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

insertMany#

Description#

Insert an array of rows into your SQL Table

/**
* @param {string} id Database id.
* @param {array} data data to insert into database.
*
* @return {object} Return object
*/

Examples#

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

findOne#

Description#

Find data in your SQL table.

/**
* @param {string} id Database id.
*
* @param {string} name Table name.
*
* @param {string} data Criteria to query database.
*
* @return {object} Return object
*/

Examples#

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

find#

Description#

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

/**
* @param {string} id Database id.
*
* @param {string} name Table name.
*
* @param {string} data Criteria to query database.
*
* @return {object} Return object
*/

Examples#

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

update#

Description#

Update data in your database.

/**
* @param {string} id Database id.
*
* @param {string} name Table name.
*
* @param {string} data Criteria to query database.
*
* @param {object} newData Updated data.
*
* @return {object} Return object
*/

Examples#

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

delete#

Description#

Delete rows from your database.

/**
* @param {string} id Database id.
*
* @param {string} name Table name.
*
* @param {string} data Criteria to query database.
*
* @return {object} Return object
*/

Examples#

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

count#

Description#

count rows in your database.

/**
* @param {string} id Database id.
*
* @param {string} name Table name.
*
* @param {string} data Criteria to query database.
*
* @return {object} Return object
*/

Examples#

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

execute#

Description#

Execute custom/complex statements on your database.

/**
* @param {string} id Database id.
*
* @param {string} query SQL Statement.
*
* @return {object} Return object
*/

Examples#

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