Web Modeler SDK Reference
The web modeler SDK is available in the web modeler, It allows users access resources from user interface and execute complexe computational in the user interface run time.
The SDK has the following classes
class Softyflow {}
class SFProjects {}
class Users {}
class Groups {}
class Collection {}
class SQLDatabase {}
class SoftyTables {}
class CustomList {}
class Report {}
class Instance {}
class Task {}
class Api {}
class Email {}
class DataSource {}
class File {}
In the following sections we will explicit each class and the allowed methods.
Every method of the SDK is an HTTP call to the SoftyFlow server, run with the rights of the connected user: his roles on the resource (collection, report, EDS, SoftyTable…) and his IDE access. Since 8.6, the server also checks what the page sends:
Errors: a refused call rejects the promise with the err object sent by the server, whose message explains the refusal (try { … } catch (e) { console.log(e.message) }). For Api.invoke, e is usually the message itself (a string), as the API sends it. The HTTP status is not part of the rejected value (e.status is undefined; only an answer without a SoftyFlow error body, such as a network error, gives an Error with message and status): read it in the network tab of the browser. It depends on the endpoint: most refusals now answer 400 (invalid request), 401 (not logged in), 403 (right missing) or 404 (not found) instead of a 500, but the refusals of SoftyTables (empty criteria, column not published, readable database errors) still answer 500 with a readable message, and invalid data sent to Users or Groups (create, update) answers 403 with the message of the validation.
Aggregation pipelines (aggregate of Projects, Users, Groups, Collection, Report, Instance and Task, setListFromCollectionAggregation, setListFromReportAggregation, aggregateQuery): the pipeline is an array of stage objects, [{ $match: … }, { $group: … }], never an array inside an array. The server refuses with the status 400 and a message starting with Aggregation refused::
- the stages that write into the database:
$out, $merge; - the operators that run JavaScript on the database server:
$function, $accumulator, $where; - every stage that is not a read stage (change streams, diagnostics, unknown names);
at any depth: inside a $facet, in the sub-pipeline of a $lookup or a $unionWith, in an expression.
Reading another collection: $lookup, $graphLookup and $unionWith may only read the collection(s) of the call itself, or another SoftyFlow collection <name>_<mode> (for example orders_prod) that the connected user may read with his roles of that environment (read right). The users collection is never a target.
Criteria: the criteria of find, count, findAndCount and updateMany (Collection, Users, Groups, Instance, Task, histories) refuse $where, $function and $accumulator (400).
User fields: the password, the password history, the reset tokens, the captcha and the Google Drive tokens are never returned by Users, even when a pipeline asks for them.
Values sent as JSON: the arguments travel as JSON. A regular expression (/p/i, new RegExp('p', 'i')) becomes {} on the way and matches nothing: write { $regex: 'p', $options: 'i' }.
Only SF.collection.aggregate of the process modeler SDK, which reads the database directly, runs without these restrictions: page code that used a refused stage on a collection must move it into SF.collection.aggregate, in an API or a process script. SF.report.aggregate, called from a script, goes through HTTP and the same check (the stages above are refused; only the check of the $lookup targets is relaxed for the scripts): moving a refused report pipeline into a script does not help.
The Softyflow class has the Softyflow system methods
This class is instantiated by default as object named SF when the user interface is loaded, so you can use methods directly by calling them via object "SF"
let currentMode = this.SF.getSF_mode();
Is a function that return the mode of the running user interface
| Type | Description |
|---|
string | Return string ('test', 'uat', 'prod') |
let currentMode = this.SF.getSF_mode();
Is a function that return the version of the running user interface
| Type | Description |
|---|
string | Return string ('test', 'uat', 'prod') |
let currentVersion = this.SF.getSF_Version();
Is a function that return the query parameters
| params | Description |
|---|
| select | optional. The fields to select (fields: SF_mode, SF_version, SF_screen) |
| Name | Type | Description |
|---|
select | string | The selected fields |
| Type | Description |
|---|
string | Return string |
let currentMode = this.SF.getSF_mode('SF_mode SF_version');
console.log(currentMode)
Is a function that start specific process
| Name | Type | Description |
|---|
id | string | Process id |
body | object | Json of process variables |
| Type | Description |
|---|
promise | Return promise |
let variables = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await this.SF.startProcess('processId', variables);
On a public page opened by an anonymous visitor, startProcess and validateTask call validateCaptcha by themselves and send the token with the call.
Is a function that runs a Google reCAPTCHA v3 check for an action and returns the generated token. It uses the Site key set in Settings › Keys & secrets (reCAPTCHA v3).
| Name | Type | Description |
|---|
action | string | The name of the action used for the reCAPTCHA v3 check. |
| Type | Description |
|---|
Promise<string> | Resolves to the reCAPTCHA token (an empty string if reCAPTCHA fails in the browser). |
let token = await this.SF.validateCaptcha("login_form");
Is a function that allow to you to save the user interface state
| Name | Type | Description |
|---|
id | string | interface id |
body | object | Json of interface variables |
| Type | Description |
|---|
promise | Return promise |
let variables = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await this.SF.saveNew('interfaceId', variables);
Is a function that allow to you to save the task interface state
| Name | Type | Description |
|---|
id | string | task id |
body | object | Json of task variables |
| Type | Description |
|---|
promise | Return promise |
let variables = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await this.SF.saveTask('taskId', variables);
Is a function that allow to validate Task
| Name | Type | Description |
|---|
id | string | task id |
body | object | Json of task variables |
| Type | Description |
|---|
promise | Return promise |
let variables = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await this.SF.validateTask('taskId', variables);
Is a function that allow to get pending Task assigned to connected user.
| Name | Type | Description |
|---|
limit | string | limit of result per page. |
page | string | number of page |
dueDate | string | related date. |
fields | string | fileds. |
| Type | Description |
|---|
promise | Return promise |
await this.SF.getUserPendingTask('limit', 'page', 'dueDate', 'fields');
Is a function that uploads an image to the server using a multipart/form-data POST request.
| Name | Type | Description |
|---|
data | FormData | A FormData object containing the image file and any additional metadata. |
| Type | Description |
|---|
Promise<object> | Returns a Promise that resolves to the response data from the server. |
const formData = new FormData();
formData.append("profileImage", file);
let response = await this.SF.uploadImage(formData);
Is a function that allow to set list of data from a specific collection.
| Name | Type | Description |
|---|
collection | string | collection ID. |
criteria | object | Query json. |
limit | string | limit of result. |
sort | object | Sort option: { by: 'field', direction: 1 or -1 }. |
| Type | Description |
|---|
promise | Return promise |
let criteria = {
firstName: { $regex: "p", $options: "i" }
}
await this.SF.setListFromCollection('collectionId', criteria, 10, { by: 'createdAt', direction: -1 });
Is a function that performs an aggregation operation on a specified collection using the provided aggregation pipeline.
| Name | Type | Description |
|---|
collection | string | The name or ID of the target collection to aggregate. |
aggreg | Array<object> | An array of aggregation pipeline stages (MongoDB aggregation framework). |
| Type | Description |
|---|
Promise<Array> | Returns a Promise that resolves to the result of the aggregation query. |
let results = await this.SF.setListFromCollectionAggregation("customers", [
{ $match: { age: { $gte: 18 } } },
{ $group: { _id: "$country", count: { $sum: 1 } } }
]);
The pipeline is checked by the server (see Rules applied by the server).
Is a function that performs a dynamic aggregation query on a report collection, using filters, sorting, and limit options.
| Name | Type | Description |
|---|
report | string | The ID or name of the report collection. |
query | object | An object representing filter conditions using custom or MongoDB operators. |
[limit] | number | (Optional) Limits the number of returned documents. |
[sort] | object | (Optional) Sorting options with by field and direction (-1 or 1). |
| Type | Description |
|---|
Promise<Array> | Returns a Promise that resolves to the result of the aggregation. |
let result = await this.SF.setListFromReport("monthly_sales", {
SF_createdBy: "admin@example.com",
region: "NA"
}, 10, { by: "createdAt", direction: -1 });
Is a function that performs a custom aggregation on a report instance using a provided aggregation pipeline.
| Name | Type | Description |
|---|
report | string | The ID or name of the report collection. |
aggreg | Array<object> | The aggregation pipeline to execute. |
| Type | Description |
|---|
Promise<Array> | Returns a Promise that resolves to the result of the aggregation. |
let data = await this.SF.setListFromReportAggregation("monthly_reports", [
{ $match: { status: "completed" } },
{ $group: { _id: "$region", total: { $sum: "$amount" } } }
]);
The pipeline is checked by the server (see Rules applied by the server).
Is a function that runs a SQL statement on an external database (EDS) and returns its rows. It uses execute: one of the connected user's roles must hold the four rights (create, read, update and delete) on the EDS, otherwise the call is refused (403). Four rights spread over two roles are not enough.
| Name | Type | Description |
|---|
clientDatabase | string | clientDatabase ID. |
query | string | SQL statement. |
| Type | Description |
|---|
promise | Return promise |
await this.SF.setListFromSQL('clientDatabaseID', "SELECT * FROM client WHERE code='MMA'");
Is a function that allow to set list of data from CustomList.
| Name | Type | Description |
|---|
CustomList | string | CustomList ID. |
| Type | Description |
|---|
promise | Return promise |
await this.SF.setListFromCustomList('CustomListID');
Is a function that runs an aggregation on a resource: an aggregation pipeline for a collection, a report, the users or the projects; a SQL statement for a SoftyTable or an external database.
| Name | Type | Description |
|---|
type | string | type of the resource (collection, report, users, projects, softyTable, external databases). |
id | string | Id of the resource. |
query | array or string | Aggregation pipeline (array of stages), or SQL statement for softyTable (@table(<table>) names the table of the current environment) and external databases. |
| Type | Description |
|---|
promise | Return promise |
await this.SF.aggregateQuery('collection', '610c0343f6ebc7ddcb49cc3b', [
{ $match: { value: "it" } }
]);
The pipeline is checked by the server (see Rules applied by the server).
Is a function that allow to delete a file using it ID.
| Name | Type | Description |
|---|
id | string | Id of the resource. |
| Type | Description |
|---|
promise | Return promise |
await this.SF.deleteFile('610c0343f6ebc7ddcb49cc3b');
The Projects class reads the interfaces shown on the home page of the portal. It requires the IDE access: on the page of an end user without it, the call is refused (403).
In the page code, the class is named SFProjects:
const projects = new SFProjects({ mode: this.SF_mode });
The mode given to the constructor is not sent to the server.
Runs an aggregation on the interfaces shown on the home page (the interfaces whose latest version has Show on the home page in its page settings), not on the projects themselves. Each document has the fields _id (id of the interface), name, homePageThumbNail (icon), section (the Workspace that groups the tiles), role, colorHome (tile colour) and projectId; your stages are added after these fields are built.
| Name | Type | Description |
|---|
aggregation | array | aggregation array, run on the documents described above |
| Type | Description |
|---|
promise | Resolves to an array of two elements: [documents, count] (the result of the pipeline and the number of documents) |
let aggregation = [
{
"$group": {
"_id": "$projectId",
"total": { "$sum": 1 }
}
}
]
let [perProject, count] = await projects.aggregate(aggregation);
let [inSection] = await projects.aggregate([{ "$match": { "section": "Purchasing" } }]);
The pipeline is checked by the server (see Rules applied by the server): a $lookup may only read the interfaces, their versions and the projects.
The Users class has the methods that will allow you to manage the users.
const users = new Users();
create, update, delete, addRole and removeRole require the IDE access: they fail (403) for an end user without it. For a user without IDE access, find, findAndCount and aggregate return only the public fields: firstName, lastName, fullName (aggregate), email, lg, profilePicture and the roles (group, group_test, group_uat). The secret fields (password, password history, reset tokens, captcha, Google Drive tokens) are never returned.
Allow to create a new user. Requires the IDE access.
| Name | Type | Description |
|---|
data | object | Json of the user data |
| Type | Description |
|---|
promise | Return promise |
The accepted user data. A field outside this list, a missing required field or a value of the wrong type is refused with a 403 and the message of the validation (for example "nickname" is not allowed):
| Field | Description |
|---|
| email | Required and unique. The email of the user (string) |
| lastName | Required. The last name of the user (string) |
| firstName | Required. The first name of the user (string) |
| group | Required. The ids of the PROD roles of the user (array) |
| group_test, group_uat | Optional. The ids of the TEST and UAT roles (array) |
| ideAccess | Required. Access to the IDE (boolean) |
| blocked | Required. Blocks the user (boolean) |
| metadata_test, metadata_uat, metadata_prod | Optional. The user attributes of each environment (json) |
| lg | Optional. The language of the user (string) |
| ideLanguage | Optional. The language of the IDE for the user (string) |
| ressourcesAccess | Optional. The access of the user to the IDE resources (json) |
| represent | Optional. The delegations of the user (array) |
| blockBasicAuth | Optional. Refuses the sign-in with email and password: the user must use another authentication method, such as SSO (boolean) |
| sendMail | Optional. Sends the welcome email (boolean) |
| getPassword | Optional. Returns the generated password in the response, next to _id and email (boolean) |
let user = {
email: "jean.dupont@example.com",
lastName : "Dupont",
firstName: "Jean",
group: [],
metadata_prod: {},
ideAccess: false,
blocked: false
}
await users.create(user);
Allow to update a user. Requires the IDE access.
| Name | Type | Description |
|---|
id | string | user id. |
data | object | user data. |
| Type | Description |
|---|
promise | Return promise |
The same data as for the creation of a user: email is required (the current email, or the new one), the other fields are optional; sendMail, getPassword and represent are not accepted (403).
let newData = {
email: "jean.dupont@example.com",
ideAccess: false
}
await users.update("userId", newData);
Allow to delete a user. Requires the IDE access.
| Name | Type | Description |
|---|
id | string | user id. |
| Type | Description |
|---|
promise | Return promise |
await users.delete("userId");
Allow to get a user by id.
| Name | Type | Description |
|---|
id | string | user id. |
| Type | Description |
|---|
promise | Return promise |
let user = await users.findById("userId");
Allow to list the users.
| Name | Type | Description |
|---|
criteria | object | Query json. |
| Type | Description |
|---|
promise | Return promise |
let criteria = {
firstName: { $regex: "p", $options: "i" }
}
let usersList = await users.find(criteria);
Allow to get the count of users.
| Name | Type | Description |
|---|
criteria | object | Query json |
| Type | Description |
|---|
promise | Return promise |
let criteria = {
blocked: false
}
let count = await users.count(criteria);
get a list and the count of users
| Name | Type | Description |
|---|
body | object | Json of options. |
| Type | Description |
|---|
promise | Return promise |
This options are optional
| Option | Description |
|---|
| criteria | Specifies selection filter (default : {}) |
| fields | Select specific fields (example: "createdAt email") |
| limit | Number of instances returned (default : 100/ no limit : 0) |
| page | Page number depends on the limit (default : 0) |
| sortby | Sorts the results by key (default : createdAt) |
| direction | Ascending (1) or descending (-1) order (default : -1) |
let body = {
criteria: {
firstName: { $regex: "p", $options: "i" }
},
limit: 10,
page: 0,
sortby: "createdAt",
direction: -1
}
let res = await users.findAndCount(body);
let usersList = res.data;
let count = res.count;
Aggregation operations process data records and return computed results
| Name | Type | Description |
|---|
aggregation | array | aggregation array |
| Type | Description |
|---|
promise | Return promise |
let aggregation = [
{
"$match": { "firstName": { "$regex": "z", "$options": "i" } }
},
{
"$project" : {
"_id": 1,
"firstName": 1,
"lastName": 1,
"email": 1
}
}
]
let usersList = await users.aggregate(aggregation);
The pipeline is checked by the server (see Rules applied by the server): a $lookup may read the roles (groups) and the SoftyFlow collections the user may read, never users; the secret fields are removed before the pipeline runs.
Add role to user using user ID & group ID.
| Name | Type | Description |
|---|
userId | string | user ID. |
groupid | string | group ID. |
mode | string | mode of the running user. interface |
| Type | Description |
|---|
promise | Return promise |
await users.addRole("userId","groupId","SF_mode");
Requires the IDE access.
Remove role from user using user ID & group ID.
| Name | Type | Description |
|---|
userId | string | user ID. |
groupid | string | group ID. |
mode | string | mode of the running user interface |
| Type | Description |
|---|
promise | Return promise |
await users.removeRole("userId","groupId","SF_mode");
Requires the IDE access.
The Groups class has the methods that will allow you to manage user groups.
const groups = new Groups();
create, update, delete and groupUsers require the IDE access: they fail (403) for an end user without it.
Find a group by its unique identifier.
| Name | Type | Description |
|---|
id | string | Group ID |
| Type | Description |
|---|
promise | Returns group data |
let group = await groups.findById("groupId123");
Find groups based on a filter criteria.
| Name | Type | Description |
|---|
criteria | object | Search criteria object |
| Type | Description |
|---|
promise | Returns array of groups |
let list = await groups.find({ name: { $regex: "admin", $options: "i" } });
Count the number of groups that match the criteria.
| Name | Type | Description |
|---|
criteria | object | Filter criteria |
| Type | Description |
|---|
promise | Returns count |
let total = await groups.count({ type: "system" });
Find groups and return both the results and the total count.
| Name | Type | Description |
|---|
body | object | Request body with filters and pagination |
| Type | Description |
|---|
promise | Returns object { data, count } |
let result = await groups.findAndCount({ limit: 10, offset: 0 });
Aggregation operations process data records and return computed results.
| Name | Type | Description |
|---|
aggregation | array | Aggregation pipeline array |
| Type | Description |
|---|
promise | Returns aggregation result |
let aggregation = [
{ $match: { type: "system" } },
{ $group: { _id: "$status", total: { $sum: 1 } } }
];
let stats = await groups.aggregate(aggregation);
The pipeline is checked by the server (see Rules applied by the server): a $lookup may read the roles and the SoftyFlow collections the user may read, never users.
Creates a new group (role). Requires the IDE access.
| Name | Type | Description |
|---|
body | object | Group data: name (required), description, projects (ids of projects), tag, projectId. Any other field is refused. |
| Type | Description |
|---|
promise | Returns the created group |
let newGroup = await groups.create({ name: "Developers", description: "Development team" });
Updates an existing group by ID. Requires the IDE access.
| Name | Type | Description |
|---|
id | string | Group ID |
body | object | Group data, same fields as create (name stays required) |
| Type | Description |
|---|
promise | Returns the updated group |
let updated = await groups.update("groupId123", { name: "Admins Updated" });
Deletes a group by ID. Requires the IDE access.
| Name | Type | Description |
|---|
id | string | Group ID |
| Type | Description |
|---|
promise | Returns the deletion result |
await groups.delete("groupId123");
Retrieve the users belonging to a specific group. Requires the IDE access.
| Name | Type | Description |
|---|
id | string | Group ID |
| Type | Description |
|---|
promise | Returns array of users in the group |
let users = await groups.groupUsers("groupId123");
The collection class has the methods that will allow you to manage your collection
You can instantiate a Collection class with id or name of collection. You can add mode option
| Option | Description |
|---|
| id | Required. id or name of collection |
| mode | optional. Specifies mode of collection (default : "test") |
const collection = new Collection({ id: 'collectionId', mode: this.SF_mode });
Each method needs a right of the connected user's roles on the collection: create for insert and insertMany, update for update, updateMany and massUpsert, read for find, findById, count and aggregate, delete for delete. Pages keep document ids as strings: in the criteria of find, count and updateMany (without upsert), and in the first $match of aggregate, an _id given as a 24-character hexadecimal string also matches the ObjectId.
Allow to insert a json into a collection
| Name | Type | Description |
|---|
data | object | Json of a value to be inserted in to the collection. |
| Type | Description |
|---|
promise | Return promise |
await collection.insert({ name: "name1", type : "type1" });
Allow to insert an array of json in to a collection.
| Name | Type | Description |
|---|
data | object | Json of a value to be inserted in to the collection. |
| Type | Description |
|---|
promise | Return promise |
await collection.insertMany([{label : "IT", value : "it"}]);
update all the documents that satisfies the specified query criteria .
| Name | Type | Description |
|---|
criteria | object | Query json. |
data | object | Json of the fields to set (an object, not an array). |
options | object | Json of options, for example { upsert: true } |
| Type | Description |
|---|
promise | Return promise |
let criteria = {
firstName: { $regex: "p", $options: "i" }
}
await collection.updateMany(criteria, { type: "type2" }, { upsert: true });
data must be an object: an array or another value is refused (400 value must be an object).options.upsert creates a document when nothing matches only if one of the user's roles has the create right on the collection. Without it, only the existing documents are updated and, if nothing matches, the call is refused (403 creating documents (options.upsert) requires the create right).updatedAt is set to the current date on the updated documents.
Allow to update a document in collection
| Name | Type | Description |
|---|
id | string | Document id. |
data | object | Json of a new data. |
| Type | Description |
|---|
promise | Return promise |
await collection.update("documentId", { type : "type2" });
The _id and createdAt sent in data are ignored: a form that sends back the whole document does not rewrite them; updatedAt is set to the current date. An unknown id gives a 404 (Document not found), an id that is not a valid document id a 400.
Allow to save many documents in one call: a row with an _id updates that document (or creates it if it does not exist), a row without _id creates a new document.
| Name | Type | Description |
|---|
data | array | Array of documents (objects). |
| Type | Description |
|---|
promise | Resolves to the result of the bulk write (numbers of matched, modified and upserted documents) |
await collection.massUpsert([
{ _id: "6650f1c2a1b2c3d4e5f60718", status: "done" },
{ label: "New row", status: "todo" }
]);
- Requires the update right on the collection; creating documents also requires the create right. Without it, a row without
_id is refused (403 creating documents requires the create right) and nothing is written; the rows with an _id only update existing documents. createdAt of an existing document is kept, updatedAt is set to the current date; a new document gets both.data must be an array of objects (400 otherwise); an _id that is not a valid document id is refused (400).
Allow to delete a document from collection
| Name | Type | Description |
|---|
id | string | Document id. |
| Type | Description |
|---|
promise | Return promise |
await collection.delete("documentId");
Allow to get a object by id from the collection
| Name | Type | Description |
|---|
id | string | Document id. |
| Type | Description |
|---|
promise | Return promise |
let document = await collection.findById(id);
Allow to select the documents in a collection
| Name | Type | Description |
|---|
body | object | Json of options. |
| Type | Description |
|---|
promise | Return promise |
This options are optional
| Option | Description |
|---|
| criteria | Specifies selection filter (default : {}) |
| limit | Number of documents returned (default : 100/ no limit : 0) |
| page | Page number depends on the limit (default : 0) |
| sortby | Sorts the results by key (default : createdAt) |
| direction | Ascending (1) or descending (-1) order (default : -1) |
let body = {
criteria: {
name: { $regex: "p", $options: "i" },
type: "type1"
},
limit: 10,
page: 0,
sortby: "createdAt",
direction: -1
}
let documents = await collection.find(body);
Allow to get the count of documents that would match a query for the collection
| Name | Type | Description |
|---|
criteria | object | Query json |
| Type | Description |
|---|
promise | Return promise |
let count = await collection.count({ type: "type1" });
Aggregation operations process data records and return computed results
| Name | Type | Description |
|---|
aggregation | array | aggregation array |
| Type | Description |
|---|
promise | Return promise |
let aggregation = [
{
"$match": { "type": "type1" }
},
{
"$project" : {
"_id": 1,
"name": 1
}
}
]
let documents = await collection.aggregate(aggregation);
The pipeline is checked by the server (see Rules applied by the server): no $out, $merge, $function, $accumulator or $where; a $lookup may read this collection or another SoftyFlow collection the user may read (for example { $lookup: { from: "clients_" + this.SF_mode, localField: "clientId", foreignField: "_id", as: "client" } }), never users.
Manage your external SQL Databases Through the SQLDatabase class.
You can instantiate an SQL class with id and mode(optional).
| Option | Description |
|---|
| id | Required. id or name of Database |
| mode | optional. Specifies mode of Database (default : "test") |
const sql = new SQLDatabase({ id: '610c0343f6ebc7ddcb49cc3b', mode: this.SF_mode});
The criteria (query) can be a SQL condition written as a string ("code='MMA'") or an object whose keys are columns ({ code: 'MMA' }). Each method needs a right of the connected user's roles on the EDS: read for findOne, find and count, create for insert and insertMany, update for update, delete for delete, and, for execute, one role holding the four rights (create, read, update and delete).
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 page, the call is refused (400
EDS "<name>" is not configured in UAT, or TEST, PROD). - Update and delete need a selection: on a SQL database (MySQL, PostgreSQL, Oracle Database, Microsoft SQL Server, Snowflake), an
update or a delete whose selection is empty is refused and nothing is changed: an empty string, an empty object, or an object whose values are undefined (they are dropped on the way, for example { id: row._id } on a row that has id but no _id). The answer is a 400 Empty selection: the update was not executed (… to update every row on purpose, use the string query "1=1"). To target every row on purpose, pass the string "1=1". The page actions that update or delete EDS rows check it before the call too (Empty selection (id is undefined): the delete was not executed). - SQL text of a user without the four rights: when none of the connected user's roles holds the four rights (create, read, update, delete) on the EDS (four rights spread over two roles do not count), the SQL text he sends (the table name, or a
SELECT used as source, and a criteria written as a string) must stay one read statement: no second statement, no comment that hides the end of the query, no write or administration statement, no server function that waits, reads files or reaches other servers (400 otherwise). execute is refused (403).
Get a table row data
| Name | Type | Description |
|---|
tableName | string | table name. |
Criteria | string | query table. |
let res = await sql.findOne("client", "code='MMA'");
list multiple rows from sql table
| Name | Type | Description |
|---|
tableName | string | table name. |
options | string | query table. |
let res = sql.find("client", "code='MMA'")
Get the row count for a table with a criteria
| Name | Type | Description |
|---|
tableName | string | table name. |
options | string | query table. |
| Type | Description |
|---|
array | array with one element contining count |
let count = await sql.count("client", "code='MMA'");
Execute a custom query on the database. One of the connected user's roles must hold the four rights (create, read, update and delete) on the EDS: refused (403) otherwise.
| Name | Type | Description |
|---|
query | string | string of query. |
| Type | Description |
|---|
array | Return array. |
sql.execute("INSERT INTO client(code, intitule, representant, codepostal) VALUES('MDSX', 'holder', 'holder', 14000)")
Insert one row into a table.
| Name | Type | Description |
|---|
tableName | string | table name. |
data | object | JSON body. |
sql.insert("client", {
code: 'HelloWord',
codepostal: 14000
}
Insert multiple rows into
| Name | Type | Description |
|---|
tableName | string | table name. |
data | array | JSON body. |
sql.insertMany("client", [
{ code: '#1' },
{ code: '#2' }
])
Update rows.
| Name | Type | Description |
|---|
tableName | string | table name. |
query | string or object | criteria selecting the rows to update (required, see above). |
data | object | updated JSON body. |
sql.update('client', "code='MMA'",
{
code: "MQS"
})
sql.update('client', "1=1", { active: 0 })
Delete row/rows in your table.
| Name | Type | Description |
|---|
tableName | string | table name. |
query | string or object | criteria selecting the rows to delete (required, see above). |
sql.delete("client", "id=223")
sql.delete("client", { id: 223 })
The SoftyTables class provides methods to interact with SoftyTable resources, allowing you to perform CRUD operations, execute queries, and manage table data from the web interface.
You can instantiate a SoftyTables class with id and mode options.
| Option | Description |
|---|
| id | Required. id of the SoftyTable |
| mode | optional. Specifies mode of SoftyTable (default : "test") |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
Behaviour since 8.6 (the same server rules as SF.softyTable in the process modeler SDK):
- Rows read:
find and findById 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). findById also returns, for each many-to-many relation, the ids of the linked rows in <column>: a form that reads a row and saves it back keeps its links. - Stable paging:
find 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: [] }) and change nothing (A criteria is required to update many rows, A criteria is required to delete many rows, use clear to delete all rows). Use clear to empty the table; to update every row on purpose, pass an explicit criteria such as { id: { $gt: 0 } }. - Columns not published yet: in UAT and PROD,
insert, insertMany, 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. - Readable database errors: a value already used in a unique column (
email = jean.dupont@example.com : this value is already used by another row), a linked row that does not exist (client_id = 42 : the linked row does not exist), the delete of a row that other rows point to (This row is linked to rows of the table invoices : delete or detach them first) or a value of the wrong type (amount : invalid value "abc", integer expected).
Retrieve a single row from a SoftyTable by its ID.
| Name | Type | Description |
|---|
rowId | string | The ID of the row |
| Type | Description |
|---|
promise | Resolves to the row data, with <fk>_record (parent row of each foreign key) and the ids of the linked rows of each many-to-many relation |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
let row = await softyTable.findById('12345');
List rows from a SoftyTable with optional filtering, sorting, and pagination.
| Name | Type | Description |
|---|
body | object | JSON of options (criteria, limit, page, sortby, direction) |
| Type | Description |
|---|
promise | Resolves to an array of table rows |
These options are optional
| Option | Description |
|---|
| criteria | Specifies selection filter with where clause (default : {}) |
| limit | Number of rows returned (default : no limit) |
| page | Page number depends on the limit (default : 0) |
| sortby | Sorts the results by field name (default : createdAt), then by id |
| direction | Ascending (1) or descending (-1) order (default : ascending) |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
let rows = await softyTable.find({});
let body = {
criteria: {
where: { status: 'active' }
},
limit: 50,
page: 0,
sortby: 'createdAt',
direction: -1
}
let activeRows = await softyTable.find(body);
Count the number of rows in a SoftyTable with optional filtering.
| Name | Type | Description |
|---|
criteria | object | Query criteria with optional where clause |
| Type | Description |
|---|
promise | Resolves to an object with count property |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
let result = await softyTable.count({});
let result = await softyTable.count({
criteria: { where: { status: 'active' } }
});
Get both a list of rows and the total count matching the criteria.
| Name | Type | Description |
|---|
body | object | JSON of options (criteria, limit, page, sortby, direction) |
| Type | Description |
|---|
promise | Resolves to object { data, count } |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
let body = {
criteria: {
where: { status: 'active' }
},
limit: 10,
page: 0,
sortby: 'createdAt',
direction: -1
}
let result = await softyTable.findAndCount(body);
let rows = result.data;
let count = result.count;
Create a single row in a SoftyTable.
| Name | Type | Description |
|---|
body | object | The data object to insert as a row |
| Type | Description |
|---|
promise | Resolves to the created row data |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
let newRow = await softyTable.insert({
name: 'John Doe',
email: 'john@example.com',
age: 30,
status: 'active'
});
Create multiple rows in a SoftyTable at once.
| Name | Type | Description |
|---|
data | array | Array of data objects to insert |
| Type | Description |
|---|
promise | Resolves to an array of created rows |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
let newRows = await softyTable.insertMany([
{ 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 }
]);
Update a single row in a SoftyTable by its ID.
| Name | Type | Description |
|---|
rowId | string | The ID of the row to update |
body | object | The fields and values to update |
| Type | Description |
|---|
promise | Resolves to the updated row |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
let updated = await softyTable.update('12345', {
status: 'inactive',
updatedAt: new Date()
});
Update multiple rows in a SoftyTable that match specific criteria.
| Name | Type | Description |
|---|
criteria | object | Filter on the columns, written directly (no where key), for example { status: 'pending' }. Required: an empty criteria is refused |
value | object | The fields and values to update |
options | object | Additional options (optional) |
| Type | Description |
|---|
promise | Resolves to update operation result |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
let result = await softyTable.updateMany(
{ status: 'pending' },
{ status: 'active', processedAt: new Date() }
);
await softyTable.updateMany({ id: { $gt: 0 } }, { archived: true });
Delete a single row from a SoftyTable by its ID.
| Name | Type | Description |
|---|
rowId | string | The ID of the row |
| Type | Description |
|---|
promise | Resolves to deletion result |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
await softyTable.delete('12345');
Delete multiple rows from a SoftyTable that match specific criteria.
| Name | Type | Description |
|---|
criteria | object | Filter on the columns, written directly (no where key). Required: an empty criteria is refused, use clear to empty the table |
| Type | Description |
|---|
promise | Resolves to deletion result |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
await softyTable.deleteMany({ status: 'inactive' });
await softyTable.deleteMany({
createdAt: { $lt: new Date('2024-01-01') }
});
Clear all rows from a SoftyTable (delete all data).
| Type | Description |
|---|
promise | Resolves to deletion result |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
await softyTable.clear();
Retrieve options for select fields in a SoftyTable.
| Type | Description |
|---|
promise | Resolves to array of options |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
let options = await softyTable.getOptions();
Execute a custom SQL query on the SoftyTable. One of the connected user's roles must hold the four rights (create, read, update and delete) on the table: refused (403) otherwise.
Name a table with @table(<table>): the server replaces it with the table of the current environment ("my_table_sf_test" in TEST, "my_table_sf_prod" in PROD). A name that is not a SoftyTable, or a table not deployed in this environment, is refused with an error.
| Name | Type | Description |
|---|
query | string | The SQL query to execute |
options | object | Query options with replacements and type |
| Field | Type | Description |
|---|
replacements | object | Values to replace in parameterized queries |
type | string | Query type: 'SELECT', 'INSERT', 'UPDATE', 'DELETE', 'RAW', 'SHOWTABLES' |
| Type | Description |
|---|
promise | Resolves to the query results |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
let results = await softyTable.execute(
'SELECT * FROM @table(my_table) WHERE status = :status',
{
replacements: { status: 'active' },
type: 'SELECT'
}
);
let results = await softyTable.execute(
`UPDATE @table(my_table) SET status = 'processed' WHERE "createdAt" < NOW() - INTERVAL '30 days'`,
{ type: 'UPDATE' }
);
Migrate rows in a SoftyTable (for data migration operations).
| Type | Description |
|---|
promise | Resolves to migration result |
const softyTable = new SoftyTables({id: 'tableId', mode: 'test'});
let result = await softyTable.migrate();
The CustomList class has the methods that will allow you to manage your Custom List
You can instantiate a CustomList class with id of custom list. You can add other options (mode, versionId)
| Option | Description |
|---|
| id | Required. id of custom list |
| mode | optional. Specifies mode of custom list (default : "test") |
| versionId | optional. id of the version from which to get the custom list |
const customList = new CustomList({id: 'id', mode: 'test', versionId: "vId"});
Get a custom list data
| Type | Description |
|---|
promise | Return promise |
let customListData = await customList.get();
The Report class will allow you to manipulate specific report
You can instantiate a Report class with id of report. You can add mode option
| Option | Description |
|---|
| id | Required. id of the report |
| mode | optional. Specifies mode of the report (default : "test") |
const report = new Report({id: 'id', mode: 'test'});
Aggregation operations process data records and return computed results
| Name | Type | Description |
|---|
aggregation | array | aggregation array |
options | object | optional. MongoDB aggregation options, for example { allowDiskUse: true } |
| Type | Description |
|---|
promise | Return promise |
let aggregation = [
{
"$match": { "SF_status": "Running" }
},
{
"$sort": { "SF_createdAt": -1 }
}
]
let instances = await report.aggregate(aggregation);
The pipeline and the options are checked by the server (see Rules applied by the server): a $lookup may read the instances, the tasks and the SoftyFlow collections the user may read.
The Instance class has the methods that will allow you to manage the instances
const instance = new Instance();
Get a instance by id
| Name | Type | Description |
|---|
id | string | id of instance. |
| Type | Description |
|---|
promise | Return promise |
let oneInstance = await instance.findById(id);
list the instances
| Name | Type | Description |
|---|
criteria | object | Json of query. |
| Type | Description |
|---|
promise | Return promise |
let instances = await instance.find({ status: "Running" });
Allow to get the count of instances that would match a query
| Name | Type | Description |
|---|
criteria | object | Query json |
| Type | Description |
|---|
promise | Return promise |
let count = await instance.count({ status: "Running" });
get a list and the count of instances
| Name | Type | Description |
|---|
body | object | Json of options. |
| Type | Description |
|---|
promise | Return promise |
This options are optional
| Option | Description |
|---|
| criteria | Specifies selection filter (default : {}) |
| fields | Select specific fields (example: "createdAt name status") |
| limit | Number of instances returned (default : 100/ no limit : 0) |
| page | Page number depends on the limit (default : 0) |
| sortby | Sorts the results by key (default : createdAt) |
| direction | Ascending (1) or descending (-1) order (default : -1) |
let body = {
criteria: {
status: "Running"
},
limit: 10,
page: 0,
sortby: "createdAt",
direction: -1
}
let res = await instance.findAndCount(body);
let instances = res.data;
let count = res.count;
Aggregation operations process data records and return computed results
| Name | Type | Description |
|---|
aggregation | array | aggregation array |
| Type | Description |
|---|
promise | Return promise |
let aggregation = [
{
"$match": { "status": "End" }
},
{
"$project" : {
"_id": 1,
"name": 1
}
}
]
let instances = await instance.aggregate(aggregation);
The pipeline is checked by the server (see Rules applied by the server): a $lookup may read the instances, the tasks and the SoftyFlow collections the user may read.
Update an instance
| Name | Type | Description |
|---|
id | string | id of instance. |
data | object | Json of a new data. |
| Type | Description |
|---|
promise | Return promise |
await instance.update(id, { status : "End" });
Delete an instance
| Name | Type | Description |
|---|
id | string | id of instance. |
| Type | Description |
|---|
promise | Return promise |
await instance.delete(id);
Get instance history.
| Name | Type | Description |
|---|
id | string | id of instance. |
data | object | Json of data. |
| Type | Description |
|---|
promise | Return promise |
await instance.history(id, { status : "End" });
The Task class has the methods that will allow you to manage the tasks
Get a task by id
| Name | Type | Description |
|---|
id | string | id of task. |
| Type | Description |
|---|
promise | Return promise |
let oneTask = await task.findById(id);
list the tasks
| Name | Type | Description |
|---|
criteria | object | Json of query. |
| Type | Description |
|---|
promise | Return promise |
let tasks = await task.find({ instanceId: "instanceId" });
Allow to get the count of tasks that would match a query
| Name | Type | Description |
|---|
criteria | object | Query json |
| Type | Description |
|---|
promise | Return promise |
let count = await task.count({ instanceId: "instanceId" });
get a list and the count of tasks
| Name | Type | Description |
|---|
body | object | Json of options. |
| Type | Description |
|---|
promise | Return promise |
This options are optional
| Option | Description |
|---|
| criteria | Specifies selection filter (default : {}) |
| assignedToConnected | To get tasks of connected user (default : false) |
| fields | Select specific fields (example: "createdAt name status") |
| limit | Number of instances returned (default : 100/ no limit : 0) |
| page | Page number depends on the limit (default : 0) |
| sortby | Sorts the results by key (default : createdAt) |
| direction | Ascending (1) or descending (-1) order (default : -1) |
let body = {
criteria: {
status: "Running"
},
assignedToConnected: true,
limit: 10,
page: 0,
sortby: "createdAt",
direction: -1
}
let res = await task.findAndCount(body);
let tasks = res.data;
let count = res.count;
Aggregation operations process data records and return computed results
| Name | Type | Description |
|---|
aggregation | array | aggregation array |
| Type | Description |
|---|
promise | Return promise |
let aggregation = [
{
"$match": { "status": "End" }
},
{
"$project" : {
"_id": 1,
"name": 1
}
}
]
let tasks = await task.aggregate(aggregation);
The pipeline is checked by the server (see Rules applied by the server): a $lookup may read the instances, the tasks and the SoftyFlow collections the user may read.
Update an task
| Name | Type | Description |
|---|
id | string | id of task. |
data | object | Json of a new data. |
| Type | Description |
|---|
promise | Return promise |
await task.update(id, { status : "End" });
Delete an task
| Name | Type | Description |
|---|
id | string | id of task. |
| Type | Description |
|---|
promise | Return promise |
Get next value of an task.
| Name | Type | Description |
|---|
name | string | name of the variable. |
[padding] | number | Padding of result with 000000. |
mode | string | mode of the running user. |
| Type | Description |
|---|
promise | Return promise |
await task.getNextValue("name",5,"SF_mode");
Get the history of a task by its ID.
| Name | Type | Description |
|---|
id | string | Task ID |
body | object | Query parameters (optional) |
| Type | Description |
|---|
promise | Returns object { data, count } |
let log = await task.history("taskId123", {});
The Api class has the methods that will allow you to call your Apis.
You instantiate an Api class with the id of the API and the mode.
| Option | Description |
|---|
| id | Required. id of the API |
| mode | Required. Environment of the call (this.SF_mode) |
const api = new Api({ id: '6491696d1ef51ed2f7044b79', mode: this.SF_mode });
Invoke the API with a request body (a POST call to /api/v1/api/<id>?SF_mode=<mode>).
| Name | Type | Description |
|---|
body | object | Request body: the input of the API. |
| Type | Description |
|---|
promise | Resolves to the HTTP response: the result of the API is in res.data.data |
const api = new Api({ id: '6491696d1ef51ed2f7044b79', mode: this.SF_mode });
try {
const res = await api.invoke({ email: "jean.dupont@example.com", amount: 120 });
this.models.result = res.data.data;
} catch (e) {
this.$message({ type: 'error', message: String(e) });
}
- Call schema: if the API has a call schema with Refuse calls that do not match, a body that does not match is refused with a 400 and the API does not run. In the page code,
e is then the message string, Invalid request: <first error>. The HTTP response also holds details, the list of all the errors, but the page SDK does not pass it on: read it in the network tab of the browser, or from another HTTP client. - Body keys: each key of the body becomes a variable of the API code, except the keys that are not valid JavaScript names (
first-name, Nom client, default…): read them in SF_body (for example SF_body["first-name"]).
The Email class has the methods that will allow you to manage your emails.
const email = new Email();
Send an email built from a mail template.
| Name | Type | Description |
|---|
assignee | string | Email address of the recipient. |
subject | string | Subject of the email. |
variables | object | Variables used by the template. |
mailTemplate | string | Id of the mail template (file). Required. |
mailProvider | string | optional. Id of a mail provider; by default, the default provider of the platform. |
cc | string | optional. Email address(es) in copy. |
from | string | optional. Display name of the sender (for example Purchasing): the address stays no-reply@softyflow.io. When the mail provider has its own From address, that address replaces both. Do not pass an address: x@y.com would give x@y.com <no-reply@softyflow.io>. |
replyTo | string | optional. Reply-to address. |
attachements | array | optional. Ids of the files to attach. |
| Type | Description |
|---|
promise | Return promise |
const email = new Email();
await email.send(
"jean.dupont@example.com",
"Your request is approved",
{ firstName: "Jean", amount: 120 },
"6650f1c2a1b2c3d4e5f60718",
null,
"",
"Purchasing",
"purchasing@example.com",
["6650f1c2a1b2c3d4e5f60720"]
);
- A missing or invalid
mailTemplate is refused (400 Mail template not found: give the id of an existing mail template (mailTemplate)), a template that does not exist gives a 404 (Mail template not found …): before 8.6, such a call could stop the server. - These emails are always sent at once: the per-user notification settings (individual sending and digest, see Process emails and the email digest) only apply to the emails of the processes.
The DataSource class works on an external data source (EDS): source is a table name (or a SELECT used as a source) and options.query the criteria, a SQL condition written as a string or an object whose keys are columns. It follows the same rights and rules as SQLDatabase, which uses it.
const ds = new DataSource({ id: '610c0343f6ebc7ddcb49cc3b', mode: this.SF_mode });
Retrieve a single document from a data source.
| Name | Type | Description |
|---|
source | string | Name of the source |
options | object | Query options |
| Type | Description |
|---|
promise | Returns a single document |
let doc = await ds.findOne("customers", { query: { email: "jean.dupont@example.com" } });
List multiple documents from a data source.
| Name | Type | Description |
|---|
source | string | Name of the source |
options | object | query (criteria); optional sortby (column) and direction (1 ascending, any other value descending); with sortby, limit and page page the result (without sortby, they are ignored) |
| Type | Description |
|---|
promise | Returns an array of documents |
let docs = await ds.list("customers", { query: { active: 1 }, sortby: "name", direction: 1, limit: 20, page: 0 });
On 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.
Count the number of documents in a data source.
| Name | Type | Description |
|---|
source | string | Name of the source |
options | object | Query options |
| Type | Description |
|---|
promise | Returns the count of documents |
let total = await ds.count("orders", { query: "status='delivered'" });
Update documents in a data source.
| Name | Type | Description |
|---|
source | string | Name of the source |
options | object | { query }: criteria selecting the rows to update (required on a SQL database) |
data | object | Data to update |
| Type | Description |
|---|
promise | Returns update result |
await ds.update("products", { query: { stock: 0 } }, { restock: 1 });
An empty selection (no query, "", {} or values that are undefined) is refused on a SQL database (400 Empty selection: the update was not executed …); pass { query: "1=1" } to update every row on purpose.
Insert a single document into a data source.
| Name | Type | Description |
|---|
source | string | Name of the source |
data | object | Document to insert |
options | object | Additional options |
| Type | Description |
|---|
promise | Returns insert result |
await ds.insert("logs", { action: "login", userId: "abc123" }, {});
Insert multiple documents into a data source.
| Name | Type | Description |
|---|
source | string | Name of the source |
data | array | Array of documents |
options | object | Additional options |
| Type | Description |
|---|
promise | Returns insert result |
await ds.insertMany("logs", [{ action: "view" }, { action: "edit" }], {});
Delete documents from a data source.
| Name | Type | Description |
|---|
source | string | Name of the source |
options | object | { query }: criteria selecting the rows to delete (required on a SQL database) |
| Type | Description |
|---|
promise | Returns delete result |
await ds.delete("sessions", { query: { expired: 1 } });
An empty selection is refused on a SQL database (400 Empty selection: the delete was not executed …); pass { query: "1=1" } to delete every row on purpose.
Execute a SQL statement on the data source. One of the connected user's roles must hold the four rights (create, read, update and delete) on the EDS: refused (403) otherwise.
| Name | Type | Description |
|---|
source | string | The SQL statement |
options | object | Parameters for execution ({}) |
| Type | Description |
|---|
promise | Returns execution result |
await ds.execute("UPDATE jobs SET status = 'todo' WHERE status = 'failed'", {});
The File class provides methods for generating PDF files from stored HTML templates and variable contexts using API endpoints.
genratePDFWithVar and fillTemplate refuse a public file as template (403 Generation from a public file is not allowed): keep their templates private. generatePDF does not check it (it is reserved to IDE users).
Generates a PDF file by retrieving the HTML content of a file and posting it along with contextual data. Requires the IDE access (403 otherwise): it is not available on the pages of the end users, use genratePDFWithVar there.
| Name | Type | Description |
|---|
filename | string | - Desired name for the generated PDF |
fid | string | - File ID to fetch content from |
context | object | - Contextual data for PDF rendering (e.g., variables) |
| Type | Description |
|---|
Promise | - Resolves with the PDF generation response |
const file = new File();
file.generatePDF("output.pdf", "605c72...", { variables: { user: "Alice" } });
Generates a PDF from a PDF template with the given variables, and saves it as a new file (the action previewPDF uses it).
| Name | Type | Description |
|---|
name | string | - Name for the output (not directly used in the call) |
fid | string | - File ID of the template |
context | object | - { variables }: the data used for rendering the template |
| Type | Description |
|---|
Promise | - Resolves with the server response: res.data is the generated PDF file (_id, filename) |
const file = new File();
const res = await file.genratePDFWithVar("Invoice", "605c72...", { variables: { amount: 100, user: "Alice" } });
this.models.pdfUrl = `/uploads/${res.data._id}/name/${res.data.filename}`;
Conditions since 8.6:
- the user must be logged in and not blocked: an anonymous visitor of a public page gets a 401;
- the file must be a PDF template created with the PDF template editor (403
This file is not a PDF template otherwise).
As before 8.6, the template must not be a public file (403 Generation from a public file is not allowed).
Fills a document template (Word, Excel, PowerPoint, LibreOffice…) with data using the Carbone engine and saves the result as a new file, optionally converted to PDF (see SF.file.fillTemplate for the template syntax).
| Name | Type | Description |
|---|
fid | string | File ID of the template |
data | object | Data injected into the template |
pdf | boolean | optional. true to convert the result to PDF |
| Type | Description |
|---|
Promise | Resolves with the server response: res.data.data is the new file (_id, filename) |
const file = new File();
const res = await file.fillTemplate("64bfa28cfabc123...", { customerName: "Jean Dupont", amount: 1500 }, true);
this.models.pdfUrl = `/uploads/${res.data.data._id}/name/${res.data.data.filename}`;
The user must be logged in and not blocked; a public template is refused (403 Generation from a public file is not allowed).