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 query ranges, commonly used in filters and reports.

This class has no constructor, methods are accessible via the ss global object.

ss.addInfoMessage(message, params)


This method displays an informational toast message in the bottom right corner. 

You can make this method 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 dynamic parts of translated message.


Parameter(s):

NameTypeMandatoryDefault Value
messageStringYN
messageNumberYN
paramsObjectN{}


Return:

TypeDescription
VoidThis method does not return a value.


Example:

ss.addInfoMessage
ss.addInfoMessage("Three days left");
// OR
ss.addInfoMessage("{count} {noun} left", {"count": "Three", "noun": "days"});

ss.addErrorMessage(message, params)


This method displays the error toast message in the bottom right corner.

You can make this method 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 dynamic parts of translated message.


Parameter(s):

NameTypeMandatoryDefault Value
messageStringYN
messageNumberYN
paramsObjectN{}


Return:

TypeDescription
VoidThis method does not return a value.


Example:

ss.addErrorMessage
ss.addErrorMessage('"Name" cannot be blank');
// OR
ss.addErrorMessage('"{title}" cannot be blank', {title: "Name"});

ss.addSuccessMessage(message, params)


This method displays the success toast message in the bottom right corner.

You can make this method 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 dynamic parts of translated message.


Parameters:

NameTypeMandatoryDefault Value
messageStringYN
messageNumberYN
paramsObjectN{}


TypeDescription
VoidThis method does not return a value.


ss.addSuccessMessage
ss.addSuccessMessage('Successfully updated');
// OR
ss.addSuccessMessage('Successfully {action_name}', {action_name: "updated"});

ss.info(message)


This method adds an information message into the system journal (located in the Logs (sys_log) table).


Parameter(s):

NameTypeMandatoryDefault Value
messageStringYN
messageNumberYN
messageObjectYN


Return:

TypeDescription
VoidThis method does not return a value, but shows a variable message.


Example:

ss.info
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 method adds a debug message into the system journal (located in the Logs (sys_log) table).


Parameter(s):

NameTypeMandatoryDefault Value
messageStringYN
messageNumberYN
messageObjectYN


Return:

TypeDescription
VoidThis method does not return a value, but shows a variable message.


Example:

ss.debug
const insertedID = inquiry.insert();
if (insertedID == 0) {
    ss.debug(inquiry.getErrors());
} else {
    ss.debug(`Create inquiry with ID ${insertedID}`)
}

ss.warning(message)


This method adds a warning message into the system journal (located in the Logs (sys_log) table).


Parameter(s):

NameTypeMandatoryDefault Value
messageStringYN
messageNumberYN
messageObjectYN


Return:

TypeDescription
VoidThis method does not return a value, but shows a variable message.


Example:

ss.warning
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 (sys_log) table).


Parameter(s):

NameTypeMandatoryDefault Value
messageStringYN
messageNumberYN
messageObjectYN


Return:

TypeDescription
VoidThis method does not return a value, but shows a variable message.


Example:

ss.error
(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 method queues an event, basing on the name and optional parameters. 

Argument name should be equal to sys_event_register name.
Table of passed current object should be equal to sys_event_register table or the table extended from it.


Parameter(s):

NameTypeMandatoryDefault Value
nameStringYN
currentSimpleRecord objectYN
param_1stringNNULL
param_2stringNNULL
param_3stringNNULL
param_4stringNNULL
param_5stringNNULL


Return:

TypeDescription
VoidThis method does not return a value.


Example:

ss.eventQueue
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 method queues an event with a specific start time.
Argument name should be equal to sys_event_register name.
Table of passed current object should be equal to sys_event_register table.


Parameter(s):

NameTypeMandatoryDefault Value
nameStringYN
currentSimpleRecord objectYN
process_started_atSimpleDateTime objectYN
param_1stringNNULL
param_2stringNNULL
param_3stringNNULL
param_4stringNNULL
param_5stringNNULL


Return:

TypeDescription
VoidThis method does not return a value.


Example:

ss.eventQueueScheduled
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 method generates a token, when the password resetting has been requested.


Return:

TypeDescription
StringA password reset token.


Example:

generateResetToken
const resetToken = ss.generateResetToken();
ss.info(resetToken);
//Info: l_kxwLi-TsTwmgLYk3euOCeXeA14nE2U_1610699284

ss.generateUrlAction(assigned_to, script, expire_at)


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. If you need redirect it, put its address into the redirectUrl variable.

Flash message "Action done" is shown by default. To change the message text, redefine the message variable.

Flash message can be turned off. To do this, set the message = null or '''.


Parameter(s):

NameTypeMandatoryDefault Value
assigned_toStringYN
scriptStringYN
expire_atStringYN


Return:

TypeDescription
StringThe action URL.


Example:

ss.generateUrlAction
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 method returns the ID of the current application for the current user.


TypeDescription
StringThis method returns application ID.


getApplicationID
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'.


Parameter(s):

NameTypeMandatoryDefault Value
nameStringYN


Return:

TypeDescription
String Property value if available; otherwise, returns NULL.


Example:

ss.getProperty
ss.info(ss.getProperty('simple.passwordreset.enabled'));
//Info: false

ss.setProperty(name, value, description)


This method checks 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):

NameTypeMandatoryDefault Value
nameStringYN
valueStringYN
descriptionStringNNULL


Return:

TypeDescription
VoidThis method does not return a value.


Example:

ss.setProperty
ss.setProperty('user.timezone.default', 'Europe/Moscow', 'Define the default user time zone');


ss.getSession()


Use this method to get a reference to the current authorization session.


Return:

TypeDescription
SimpleSessionReference to the current session.

Example:

getSession()
const session = ss.getSession();
const ipAddress = session.getClientIP();
ss.info(ipAddress);
//Info: 127.0.0.1

ss.getUser()


This method returns the current user SimpleRecord object.


TypeDescription
SimpleRecord objectThe current user SimpleRecord object.
getUser
ss.info(ss.getUser().username);
//Info: admin

ss.getUserID()


This method returns the sys_id of the current user.


Return:

TypeDescription
StringThe sys_id value


Example:

getUserID
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(tableID,RecordID)


This method gets a table ID and a table record ID, and returns the record Document ID (32-character UUID value).


Parameter(s):

NameTypeMandatoryDefault Value
tableIDStringYN
RecordIDStringYN


Return:

TypeDescription
StringRecord DocumentID (32-character UUID value).


Example:

ss.getDocIdByIds()
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(DocID)


This method gets a record Document ID (32-character UUID value) and returns the table ID.


Parameter(s):

NameTypeMandatoryDefault Value
DocIDStringYN


Return:

TypeDescription
StringThe table ID.


Example:

ss.getTableIdByDocId()
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(DocID)


This method gets a record DocumentID (32-character UUID value) and returns the record ID.


Parameter(s):

NameTypeMandatoryDefault Value
DocIDStringYN


Return:

TypeDescription
StringThe record ID.


Example:

ss.getRecordIdByDocId()
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 the current user has a specified or admin role.

Parameter(s):

NameTypeMandatoryDefault Value
roleStringYN


Return:

TypeDescription
BooleanThis method returns true if the user has a specified or admin role, otherwise, it returns false.


Example:

ss.hasRole
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:

ss.hasRole
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.

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
ss.importIncludeScript('get_access'); return get_access();


Parameter(s):

NameTypeMandatoryDefault value
nameStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

ss.importIncludeScript
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 next. If the URL is not provided, then the current page will be 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 paths in a relative way, like shown below.

Not recommendedRecommended
https://instance.example.com/record/task/record/task

Parameter(s):

NameTypeMandatoryDefault Value
urlStringN""

Return:

TypeDescription
VoidThis method does not return a value.
setRedirect
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