This scoped server class provides methods to 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 use the ss global object to access the methods.
ss.addInfoMessage(message, params)
This method displays an Use this method to display an informational toast message in the bottom lower right corner. You can make this method display a message according according to the current user locale. To do so, in the message parameter, enter the source_messagevalue in the message parameter. See Static Interface Localization value of a record from the app category. See Localization and Multi-Language Support to learn more. The params parameter allows defining Use the params parameters to define values for the dynamic dynamic parts of the translated message.
Parameter(s):
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.addInfoMessage() |
---|
linenumbers | true |
---|
|
ss.addInfoMessage("Three days left");
// OR
ss.addInfoMessage("{count} {noun} left", {"count": "Three", "noun": "days"}); |
ss.addErrorMessage(message, params)
This method displays the Use this method to display an error toast message in message in the bottom lower right corner.You can make this method display a message according to the current user locale. To do this according to the current user locale. To do so, in the message parameter, enter the source_messagevalue in the message parameter. See Static Interface Localization value of a record from the app category. See Localization and Multi-Language Support to learn more. The params parameter allows defining Use the params parameters to define values for dynamic the dynamic parts of the translated message.
Parameter(s):
ValuemessageNumber | Yparams | Object | N | Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.addErrorMessage() |
---|
linenumbers | true |
---|
|
ss.addErrorMessage('"Name" cannot be blank');
// OR
ss.addErrorMessage('"{title}" cannot be blank', {title: "Name"}); |
ss.addSuccessMessage(message, params)
This method displays the Use this method to display a success toast message in the bottom lower right corner .You can make this method display a message according to the current user locale. To do this To do so, in the message parameter, enter the source_messagevalue in the message parameter. See Static Interface Localization value of a record from the app category. See Localization and Multi-Language Support to learn more. The params parameter allows defining values for dynamic parts of Use the params parameters to define values for the dynamic parts of the translated message.
Parameters:
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
theme | Eclipse |
---|
title | ss.addSuccessMessage() |
---|
linenumbers | true |
---|
|
ss.addSuccessMessage('Successfully updated');
// OR
ss.addSuccessMessage('Successfully {action_name}', {action_name: "updated"}); |
ss.info(message)
This Use this method to adds an information message into the system journal ( located in the Logs Main Log (sys_log)table).
Parameter(s):
ValueString | Y | N | message | Number | Y | N |
message | Object Return:
Type | Description |
---|
Void | This method does not return a value |
, but shows a variable messageExample:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.info() |
---|
linenumbers | true |
---|
|
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);
} |
ss.debug(message)
This Use this method adds to add a debug message into the system journal ( located in the Logs Main Log (sys_log)table).
Parameter(s):
Valuemessage | Number | String | Y | N | messageObject | Y | N | Return:
Type | Description |
---|
Void | This method does not return a value |
, but shows a variable messageExample:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.debug() |
---|
linenumbers | true |
---|
|
const insertedID = inquiry.insert();
if (insertedID == 0) {
ss.debug(inquiry.getErrors());
} else {
ss.debug(`Create inquiry with ID ${insertedID}`)
} |
ss.warning(message)
This Use this method adds to add a warning message into the system journal ( located in the Logs Main Log (sys_log)table).
Parameter(s):
Valuemessage | Number | String | Y | N | message | Object | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value |
, but shows a variable messageExample:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.warning() |
---|
linenumbers | true |
---|
|
const task = new SimpleRecord('task');
task.query();
while(task.next()){
ss.warning(task.sys_id);
} |
ss.error(message)
This method adds an error message into the system journal ( located in the Logs Main Log (sys_log)table) table.
Parameter(s):
ValueStringmessage | Number | Y | N |
message | Object | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value |
, but shows a variable messageExample:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.error() |
---|
linenumbers | true |
---|
|
(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); |
ss.eventQueue(name, current, param_1, param_2, param_3, param_4, param_5)
This Use this method queues to queue an event , basing based on the its name and optional parameters.
Argument The name argument should be equal to the same as the record name in the Event Registers (sys_event_register name) table.
Table The table of the passed current object should be equal to the same as the table specified in the record of the Event Register (sys_event_register) table or the table extended from it.
Parameter(s):
Valuevalue |
---|
name | String | Y | N |
current | SimpleRecord object | Y | N |
param_1 |
stringNULLstringNULLstringNULLstringNULLstringNULL Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.eventQueue() |
---|
linenumbers | true |
---|
|
if (current.state != '10') { // Not Closed
ss.eventQueue('incident.close', current, ss.getUserID());
} |
ss.eventQueueScheduled(name, current, process_started_at, param_1, param_2, param_3, param_4, param_5)
This Use this method queues to queue an event with a specific start and run it at a specified time.
Argument The name argument should be equal to the same as the record name in the Event Registers (sys_event_register name) table.
Table The table of the passed current object should be equal to the same as the table specified in the record of the Event Register (sys_event_register) table.
Parameter(s):
Valuevalue |
---|
name | String | Y | N |
current | SimpleRecord object | Y | N |
process_started_at | SimpleDateTime object | Y | N |
param_1 |
stringNULLstringNULLstringNULLstringNULLstringNULL Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.eventQueueScheduled() |
---|
linenumbers | true |
---|
|
if (current.state != '10') { // Not Closed
const plusThreeDays = new SimpleDateTime(); // now
plusThreeDays.addDays(3); // + 3 days
ss.eventQueueScheduled('incident.autoclose', current, plusThreeDays, ss.getUserID());
} |
ss.generateResetToken()
This Use this method to generates a token, for example, when the password resetting has been requested.
Return:
Type | Description |
---|
String | A This method returns a password reset token. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.generateResetToken() |
---|
linenumbers | true |
---|
|
const resetToken = ss.generateResetToken();
ss.info(resetToken);
//Info: l_kxwLi-TsTwmgLYk3euOCeXeA14nE2U_1610699284 |
ss.generateUrlAction(
assigned_touserId, script, expire
_at)
This method returns the Use this method to return a URL. After following it, the script specified by in the script parameter is executed.
By default, the main page opens after following the URL. If you need redirect it, put To redirect a user to another page, enter its address into the redirectUrl variable variable within the script.
Flash A flash message "Action done
" is shown by default. To change the message text, redefine the message variable variable within the script.
Flash message can be turned off. To do thisTo deactivate the flash message, set the message = variable as null or ' ''.
Parameter(s):
Name | Type | Mandatory | Default Valuevalue |
---|
assigned_touserId | String | Y | N |
script | String | Y | N |
expire_at | String | Y | N |
Return:
The This method returns the action URL. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.generateUrlAction() |
---|
linenumbers | true |
---|
|
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 |
ss.getApplicationId()
This application returns Use this method to return the ID of the current application for that the current user is using at the moment.
Return:
Type | Description |
---|
String | This method returns the application ID. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.getApplicationID() |
---|
linenumbers | true |
---|
|
const appId = ss.getApplicationId();
ss.info(appId);
//Info: 155931135900000002 |
ss.getProperty(name)
This method returns the value from the 'sys_property' basing on the 'name'Use this method to return a value from the specified in the name parameter record of the System Properties (sys_property) table.
Parameter(s):
Return:
String | String | This method returns the property |
Property value if available; otherwise, the method returns |
NULLExample:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.getProperty() |
---|
linenumbers | true |
---|
|
ss.info(ss.getProperty('simple.passwordreset.enabled'));
//Info: false |
ss.setProperty(name, value, description)
This method checks if Use this method to verify, using the name parameter that there is a record in the System Property (sys_property) table, using the name parameter.
If the record is absentexists, the method creates a new record, otherwise, it performs the UPDATE actionupdates its value and description.
Parameter(s):
Valuevalue |
---|
name | String | Y | N |
value | String | Y | N |
description | String | N |
NULL Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.setProperty() |
---|
linenumbers | true |
---|
|
ss.setProperty('user.timezone.default', 'Europe/Moscow', 'Define the default user time zone'); |
ss.getSession()
Use this method to get a reference to information on the current authorization session.
Return:
Type | Description |
---|
SimpleSession object |
Reference to the This method returns the SimpleSession object of the current session. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getSession() |
---|
linenumbers | true |
---|
|
const session = ss.getSession();
const ipAddress = session.getClientIP();
ss.info(ipAddress);
//Info: 127.0.0.1 |
ss.getUser()
This method returns Use this method to return the SimpleRecord object of the current user SimpleRecord object.
Return:
Type | Description |
---|
SimpleRecord object |
The This method returns the SimpleRecord object of the current user |
SimpleRecord objectExample:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.getUser() |
---|
linenumbers | true |
---|
|
ss.info(ss.getUser().username);
//Info: admin |
ss.getUserID()
This Use this method to returns the sys_id of the current user ID.
Return:
The sys_id valueThis method returns the ID value of the current user. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.getUserID() |
---|
linenumbers | true |
---|
|
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) {
//...
} |
ss.getDocIdByIds(
tableIDtableId,
RecordIDrecordId)
This method gets a table ID and a table record ID, and returns the record Use this methods to return a record Document ID (32-character UUID value) basing on the table ID and the table record ID.
Parameter(s):
Name | Type | Mandatory | Default Valuevalue |
---|
tableIDtableId | String | Y | N |
RecordIDrecordId | String | Y | N |
Return:
Record DocumentID This method returns a Document ID record (32-character UUID value). |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.getDocIdByIds() |
---|
linenumbers | true |
---|
|
const docID = ss.getDocIdByIds(current.sys_db_table_id, current.sys_id);
const approval = new SimpleRecord('sys_approval');
approval.addQuery('item', docID);
approval.query(); |
ss.getTableIdByDocId(
DocIDdocId)
This method gets a record Use this method to returm the table ID basing on the Document ID record (32-character UUID value) and returns the table IDspecified.
Parameter(s):
Return:
The This method returns а table ID. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.getTableIdByDocId() |
---|
linenumbers | true |
---|
|
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 |
ss.getRecordIdByDocId(
DocIDdocId)
This Use this method gets to return a record ID basing on the DocumentID record (32-character UUID value) and returns the record IDspecified.
Parameter(s):
Return:
The This method returns a record ID. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.getRecordIdByDocId() |
---|
linenumbers | true |
---|
|
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); |
ss.hasRole(role)
This method checks whether Use this method to verify that the current user has a the specified or the admin role.
Parameter(s):
If the role specified has the Elevated privilege checkbox selected and the admin role is not elevated up to the specified one, the method returns false.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
role | String | Name | Type | Mandatory | Default value |
---|
role | String |
Return:
Type | Description |
---|
Boolean | This method returns true if the user has |
a the specified or admin role |
, ; otherwise, it returns false. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.hasRole() |
---|
linenumbers | true |
---|
|
const isUserManager = ss.hasRole('process_manager'); // true or false
return isUserManager; |
Note |
---|
The method always returns true true if a user has a specific or the admin role. To check whether verify that the user has a particular role, use the following script: Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.hasRole() |
---|
linenumbers | true |
---|
| const MANAGER_ROLE = 'process_manager';
const userHasRole = new SimpleRecord('sys_user_has_role');
userHasRole.addQuery('user_id', ss.getUserId());
userHasRole.addQuery('role_id.name', MANAGER_ROLE);
userHasRole.setLimit(1);
userHasRole.selectAttributes(['sys_id']);
userHasRole.query();
const isManager = !!userHasRole.next();
return isManager |
|
ss.importIncludeScript(name)
This method allows importing Script Includes into server-side scripts.
Note |
---|
When used in the server-side inline scripts like UI Action condition, it is mandatory using return to return the value like it shown in the example below:
ss.importIncludeScript(name)
Use this method to import script includes.
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.importIncludeScript |
---|
linenumbers | true |
---|
|
ss.importIncludeScript('get_access'); return get_access();Parameter(s):
Name | Type | Mandatory | Default value |
---|
name | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.importIncludeScript() |
---|
linenumbers | true |
---|
|
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);
} |
ss.setRedirect(url)
This method sets the URL for this transaction to which the user will be redirected nextUse this method to redirect a user to the specified URL. If the URL is not provided, then the system refreshes the current page will be reloaded after calling the method.
Info |
---|
It is not recommended to pass the an absolute URL as a parameter value for this method, because it leads to the scalability issues. Define Specify the paths in a relative way, like shown below.. See the example below: Not recommended | Recommended |
---|
https://instance.example.com/record/task | /record/task |
|
Parameter(s):
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | ss.setRedirect |
---|
linenumbers | true |
---|
|
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 |