This scoped server class provides methods to get information about the system, the current user, etc.
Many of the methods provide easy ways to include dates in the query ranges, commonly used in filters and reports.
This class has no constructor, the methods are accessible via the ss global object.
This method displays an informational toast message in the bottom right corner.
Use this method to display a message according to the current user locale. To do so, in the message parameter, enter the source_message value of a record from the app category. See Static Interface Localization to learn more. The params parameter allows defining values for the dynamic parts of the translated message.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
message | String | Y | N |
message | Number | Y | N |
params | Object | N | {} |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
ss.addInfoMessage("Three days left"); // OR ss.addInfoMessage("{count} {noun} left", {"count": "Three", "noun": "days"}); |
This method displays an error toast message in the bottom right corner.
Use this method to display a message according to the current user locale. To do so, in the message parameter, enter the source_message value of a record from the app category. See Static Interface Localization to learn more. The params parameter allows defining values for the dynamic parts of the translated message.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
message | String | Y | N |
message | Number | Y | N |
params | Object | N | {} |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
ss.addErrorMessage('"Name" cannot be blank'); // OR ss.addErrorMessage('"{title}" cannot be blank', {title: "Name"}); |
This method displays the success toast message in the bottom right corner.
Use this method to display a message according to the current user locale. To do so, in the message parameter, enter the source_message value of a record from the app category. See Static Interface Localization to learn more. The params parameter allows defining values for the dynamic parts of the translated message.
Parameters:
Name | Type | Mandatory | Default value |
---|---|---|---|
message | String | Y | N |
message | Number | Y | N |
params | Object | N | {} |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
ss.addSuccessMessage('Successfully updated'); // OR ss.addSuccessMessage('Successfully {action_name}', {action_name: "updated"}); |
This method adds an information message into the system journal (located in the Logs (sys_log) table).
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
message | String | Y | N |
message | Number | Y | N |
message | Object | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value, but shows a variable message. |
Example:
const task = new SimpleRecord('task'); task.orderByDesc('sys_created_at'); task.setLimit(1); task.selectAttributes('number'); task.query(); while(task.next()){ ss.info(task.number); } |
This method adds a debug message into the system journal (located in the Logs (sys_log) table).
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
message | String | Y | N |
message | Number | Y | N |
message | Object | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value, but shows a variable message. |
Example:
const insertedID = inquiry.insert(); if (insertedID == 0) { ss.debug(inquiry.getErrors()); } else { ss.debug(`Create inquiry with ID ${insertedID}`) } |
This method adds a warning message into the system journal (located in the Logs (sys_log) table).
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
message | String | Y | N |
message | Number | Y | N |
message | Object | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value, but shows a variable message. |
Example:
const task = new SimpleRecord('task'); task.query(); while(task.next()){ ss.warning(task.sys_id); } |
This method adds an error message into the system journal (located in the Logs (sys_log) table).
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
message | String | Y | N |
message | Number | Y | N |
message | Object | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value, but shows a variable message. |
Example:
(function executeRule(current, previous /*null when async*/ ) { const nowDateTime = new SimpleDateTime(); const targetDateTime = new SimpleDateTime(current.appropriate_datetime); const secondsLeft = targetDateTime.getNumericValue() - nowDateTime.getNumericValue(); if (secondsLeft < 1800) { // less than half an hour left ss.addErrorMessage('Appropriate Datetime cannot be less than half an hour'); ss.error(`Too Urgent Request: ${secondsLeft} to process`); current.setAbortAction(true); } })(current, previous); |
This method queues an event, basing on the name and optional parameters.
The argument name should be equal to the sys_event_register name.
A table of the passed current object should be equal to the sys_event_register table or the table extended from it.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
name | String | Y | N |
current | SimpleRecord object | Y | N |
param_1 | string | N | NULL |
param_2 | string | N | NULL |
param_3 | string | N | NULL |
param_4 | string | N | NULL |
param_5 | string | N | NULL |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
if (current.state != '10') { // Not Closed ss.eventQueue('incident.close', current, ss.getUserID()); } |
This method queues an event with a specific start time.
The argument name should be equal to sys_event_register name.
A table of the passed current object should be equal to sys_event_register table.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
name | String | Y | N |
current | SimpleRecord object | Y | N |
process_started_at | SimpleDateTime object | Y | N |
param_1 | string | N | NULL |
param_2 | string | N | NULL |
param_3 | string | N | NULL |
param_4 | string | N | NULL |
param_5 | string | N | NULL |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
if (current.state != '10') { // Not Closed const plusThreeDays = new SimpleDateTime(); // now plusThreeDays.addDays(3); // + 3 days ss.eventQueueScheduled('incident.autoclose', current, plusThreeDays, ss.getUserID()); } |
This method generates a token, when the password resetting has been requested.
Return:
Type | Description |
---|---|
String | A password reset token. |
Example:
const resetToken = ss.generateResetToken(); ss.info(resetToken); //Info: l_kxwLi-TsTwmgLYk3euOCeXeA14nE2U_1610699284 |
This method returns the URL. After following it, the script specified by the parameter is executed.
By default, the main page opens after following the URL. To redirect it, put its address into the redirectUrl variable.
A flash message "Action done" is shown by default. To change the message text, redefine the message variable.
The flash message can be turned off. To do so, set the message = null or '''.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
assigned_to | String | Y | N |
script | String | Y | N |
expire_at | String | Y | N |
Return:
Type | Description |
---|---|
String | The action URL. |
Example:
const simpleInstanceUri = ss.getProperty('simple.instance.uri'); const instanceUrl = simpleInstanceUri.startsWith('https://') ? simpleInstanceUri : 'https://' + simpleInstanceUri; const аctionScript = ` const task = new SimpleRecord('task'); task.get('${current.sys_id}'); if (task.state == '7') { // Completed task.state = '10'; // Closed task.update(); } message = null; redirectUrl = instanceUrl + '/record/task/' + current.sys_id `; const nowDateTime = new SimpleDateTime(); nowDateTime.addDays(3); const url = ss.generateUrlAction(current.getValue('caller'), аctionScript, nowDateTime.getValue()); ss.info(url); //Info: your-instance-uri.simpleone.ru/url-action/run?key=Q2GqNFRXCRY2 |
This method returns the ID of the current application for the current user.
Return:
Type | Description |
---|---|
String | This method returns application ID. |
Example:
const appId = ss.getApplicationId(); ss.info(appId); //Info: 155931135900000002 |
This method returns the value from the 'sys_property' basing on the 'name'.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
name | String | Y | N |
Return:
Type | Description |
---|---|
String | Property value if available; otherwise, returns NULL. |
Example:
ss.info(ss.getProperty('simple.passwordreset.enabled')); //Info: false |
This method verifies if there is a record in the System Property (sys_property) table, using the name parameter.
If the record is absent, the method creates a new record, otherwise, it performs the UPDATE action.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
name | String | Y | N |
value | String | Y | N |
description | String | N | NULL |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
ss.setProperty('user.timezone.default', 'Europe/Moscow', 'Define the default user time zone'); |
Use this method to get a reference to the current authorization session.
Return:
Type | Description |
---|---|
SimpleSession | Reference to the current session. |
Example:
const session = ss.getSession(); const ipAddress = session.getClientIP(); ss.info(ipAddress); //Info: 127.0.0.1 |
This method returns the current user SimpleRecord object.
Return:
Type | Description |
---|---|
SimpleRecord object | The current user SimpleRecord object. |
Example:
ss.info(ss.getUser().username); //Info: admin |
This method returns the sys_id value of the current user.
Return:
Type | Description |
---|---|
String | The sys_id value. |
Example:
const approval = new SimpleRecord('sys_approval'); approval.addQuery('approver_id', ss.getUserID()); approval.addQuery('state', 'requested'); approval.selectAttributes('sys_id'); approval.query(); if (approval.getRowCount() > 0) { //... } |
This method gets a table ID and a table record ID, and returns the record Document ID (32-character UUID value).
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
tableID | String | Y | N |
RecordID | String | Y | N |
Return:
Type | Description |
---|---|
String | A record DocumentID (32-character UUID value). |
Example:
const docID = ss.getDocIdByIds(current.sys_db_table_id, current.sys_id); const approval = new SimpleRecord('sys_approval'); approval.addQuery('item', docID); approval.query(); |
This method gets a record Document ID (32-character UUID value) and returns the table ID.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
DocID | String | Y | N |
Return:
Type | Description |
---|---|
String | A table ID. |
Example:
const tableID = ss.getTableIdByDocId(current.item); const table = new SimpleRecord('sys_db_table'); table.get(tableID); const record = new SimpleRecord(table.name); const recordID = ss.getRecordIdByDocId(current.item); record.get(recordID); ss.addInfoMessage(record.sys_created_at); //Info: 2020-05-24 16:30:21 |
This method gets a record DocumentID (32-character UUID value) and returns the record ID.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
DocID | String | Y | N |
Return:
Type | Description |
---|---|
String | A record ID. |
Example:
const tableID = ss.getTableIdByDocId(current.item); const table = new SimpleRecord('sys_db_table'); table.get(tableID); const record = new SimpleRecord(table.name); const recordID = ss.getRecordIdByDocId(current.item); record.get(recordID); ss.addInfoMessage(record.sys_created_at); |
This method checks whether the current user has a specified or admin role.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
role | String | Y | N |
Return:
Type | Description |
---|---|
Boolean | This method returns true if the user has a specified or admin role, otherwise, it returns false. |
Example:
const isUserManager = ss.hasRole('process_manager'); // true or false return isUserManager; |
The method always returns 'true' if a user has a specific or the admin role. To check whether the user has a particular role, use the following script:
|
This method allows importing Script Includes into the server-side scripts.
When used in the server-side inline scripts like a UI Action condition, it is mandatory to use return to return the value. See the example below:
|
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
name | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
ss.importIncludeScript('calculateCAB'); const approvers = []; if (!!current.customized_cab) { approvers = approvers.concat(current.customized_cab.split(',')); } if (!current.ignore_automatically_generated_cab) { const includeScriptResult = calculateCAB(current); approvers = approvers.concat(includeScriptResult); } |
This method sets the URL for this transaction to which the user will be redirected next. If the URL is not provided, the current page is reloaded after calling the method.
It is not recommended to pass the absolute URL as a parameter value for this method, because it leads to scalability issues. Define the paths in a relative way. See the example below.
|
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
url | String | N | "" |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
ss.setRedirect(`/list/${current.getTableName()}`); // Redirect to the list view of the current table ss.setRedirect('/record/task'); // Redirect to the default view of the Task table |