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,
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")
deleteOne
Description
Allow to delete a document from collection.
/**
* @param {string} collection Collection name in softyflow.
* @param {object} query Json of a value to be matched in the collection.
*
* @return {promise} Return promise
*/
Examples
await SF.collection.deleteOne("cost-centers")
delete
Description
Allow to delete multiple documents from collection.
/**
* @param {string} collection Collection name in softyflow.
* @param {object} query Json of a value to be matched in the collection.
*
* @return {promise} Return promise
*/
Examples
await SF.collection.delete("cost-centers")
aggregate
Description
Aggregation operations process data records and return computed results
/**
* @param {string} collection Collection name in softyflow.
* @param {array} aggregation aggregation array
*
* @return {promise} Return promise
*/
Examples
let aggregation = [
{
"$match": { "type": "type1" }
},
{
"$project" : {
"_id": 1,
"name": 1
}
}
]
await SF.collection.aggregate("cost-centers",[aggregation]);
cleanCollection
Description
Remove All Documents from a Collection.
/**
* @param {string} collection Collection name in softyflow.
* @return {promise} Return promise
*/
Examples
await SF.collection.cleanCollection("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' } }])
updateUserMetadataById
Description
Update user metadata using his ID.
/**
* @param {string} id user ID.
*
* @param {object} field Json of a metadata to be updated.
*
* @param {object} value Json of a value to be updated.
* @return {promise} Return promise
*/
Examples
await SF.user.updateUserMetadataById("6042551d231e8c8ade19bc09", "Manager", "test")
getUsers
Description
Get users informations.
/**
* @return {promise} Return promise
*/
Examples
await SF.user.getUsers()
getUserMetadata
Description
Get user metadata using his ID.
/**
* @param {string} id user ID.
*
* @return {promise} Return promise
*/
Examples
await SF.user.getUserMetadata("6042551d231e8c8ade19bc09")
addUserToGroup
Description
Add user to a groupe using user ID & group ID.
/**
* @param {string} userId user ID.
*
* @param {string} groupid group ID.
*
* @return {promise} Return promise
*/
Examples
await SF.user.addUserToGroup("6042551d231e8c8ade19bc09", "62c2b6f74d16c2a2c19dcdb7")
removeUserfromGroup
Description
Remove user from group using user ID & group ID.
/**
* @param {string} userId user ID.
*
* @param {string} groupid group ID.
*
* @return {promise} Return promise
*/
Examples
await SF.user.removeUserfromGroup("6042551d231e8c8ade19bc09", "62c2b6f74d16c2a2c19dcdb7")
createUser
Description
Allow to create new user.
/**
* @param {object} data Json content user data
*
* @return {promise} Return promise
*/
Data
This is the allowed user data:
field | Description |
---|---|
Required and Unique. The user email (string) | |
lastName | Required. The user last name (string) |
firstName | Required. The user first name (string) |
group | Required. The user groups ids (array) |
metadata | optional. The user metadata (json) |
ideAccess | Required. IDE access right (boolean) |
blocked | optional. User blocking (boolean) |
Examples
let user = {
email: "email@softydev.com",
lastName : "last name",
firstName: "first name",
group: [],
metadata: {},
ideAccess: true,
blocked: false
}
await SF.users.createUser(user);
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.file.getFileContentById("6042551d231e8c8ade19bc09")
getFileBufferById
Description
Get the buffer of a file using his ID
/**
* @param {string} id File ID.
*
* @return {promise} Return promise
*/
Examples
await SF.file.getFileBufferById("6042551d231e8c8ade19bc09")
generatePDFFromTemplate
Description
Get the buffer of a file using his ID
/**
* @param {string} id File ID.
*
* @param {object} context Json content pdf variables
*
* @return {promise} Return promise
*/
Examples
await SF.user.generatePDFFromTemplate("6042551d231e8c8ade19bc09",
{
"Request NO":"000018",
"tele":"XXXXXX",
"mail":"abderrafie.niya@softydev.com",
"date2":"mardi 17 mai 2022",
"service":"achat",
"direc":"casa",
"date1":"mardi 16 mai 2022"
}
)
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'")
6 - Instance
launchProcess
Description
Initiate an existing process.
/**
* @param {string} processId Process id.
*
* @return {object} Return object
*/
Examples
await SF.instance.launchProcess('610c0343f6ebc7ddcb49cc3b')
pendingTask
Description
Get Instance latest Pending Task
/**
* @param {string} instanceId instance Id.
*
* @return {object} Return object
*/
Examples
await SF.instance.pendingTask('610c0343f6ebc7ddcb49cc3b')
getMeasures
Description
Get Instance Measures
/**
* @param {string} instanceId instance Id.
*
* @return {object} Return object
*/
Examples
await SF.instance.getMeasures('610c0343f6ebc7ddcb49cc3b')
validateTask
Description
Validate Task.
/**
* @param {string} taskId task Id.
* @param {object} variables Json of variables
*
* @return {object} Return object
*/
Examples
let variables = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await SF.instance.validateTask('610c0343f6ebc7ddcb49cc3b',variables)
updateVariablesById
Description
Update variables using instance ID.
/**
* @param {string} Id instance Id.
* @param {object} data Json of variables data
*
* @return {object} Return object
*/
Examples
let data = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await SF.instance.updateVariablesById('610c0343f6ebc7ddcb49cc3b',data)