Skip to content
v2.6

System ​

System actions. For advanced users.

Static properties ​

appUrl string ​

Gets the Rulecube application URL. Ends with a forward slash, e.g. https://app.rulecube.com/

apiUrl string ​

Gets the Rulecube API URL. Ends with a forward slash, e.g. https://app.rulecube.com/api/

currentUser *{ ​

id: string,
name: string,
email: string,
displayName: string,
roles: string[],
permissions: string[]

}* Gets information about the current user.

Methods ​

alertInfo ​

javascript
alertInfo(name: string, title: string, message: string, alertOptions?: { 
    type?: "alert" | "warning" | "error",
    name?: string,
    title?: string,
    code?: any,
    property?: string,
    propertyValue?: any,
    ruleId?: any,
    priority?: number,
    group?: string,
    entityName?: string,
    message?: string,
    messageError?: string
})

Creates and triggers an alert with the given message and type 'info'.

Parameters

name string

The name.

title string

The title.

message string

The message.

alertOptions { type?: "alert" | "warning" | "error", name?: string, title?: string, code?: any, property?: string, propertyValue?: any, ruleId?: any, priority?: number, group?: string, entityName?: string, message?: string, messageError?: string}

(optional) The object containing the alert options.

Return type

void

Examples

javascript
System.alertInfo('a', 'The title', 'The message.')

alertWarning ​

javascript
alertWarning(name: string, title: string, message: string, alertOptions?: { 
    type?: "alert" | "warning" | "error",
    name?: string,
    title?: string,
    code?: any,
    property?: string,
    propertyValue?: any,
    ruleId?: any,
    priority?: number,
    group?: string,
    entityName?: string,
    message?: string,
    messageError?: string
})

Creates and triggers an alert with the given message and type 'warning'.

Parameters

name string

The name.

title string

The title.

message string

The message.

alertOptions { type?: "alert" | "warning" | "error", name?: string, title?: string, code?: any, property?: string, propertyValue?: any, ruleId?: any, priority?: number, group?: string, entityName?: string, message?: string, messageError?: string}

(optional) The object containing the alert options.

Return type

void

Examples

javascript
System.alertWarning('a', 'The title', 'The message.')

alertError ​

javascript
alertError(name: string, title: string, message: string, alertOptions?: { 
    type?: "alert" | "warning" | "error",
    name?: string,
    title?: string,
    code?: any,
    property?: string,
    propertyValue?: any,
    ruleId?: any,
    priority?: number,
    group?: string,
    entityName?: string,
    message?: string,
    messageError?: string
})

Creates and triggers an alert with the given message and type 'error'.

Parameters

name string

The name.

title string

The title.

message string

The message.

alertOptions { type?: "alert" | "warning" | "error", name?: string, title?: string, code?: any, property?: string, propertyValue?: any, ruleId?: any, priority?: number, group?: string, entityName?: string, message?: string, messageError?: string}

(optional) The object containing the alert options.

Return type

void

Examples

javascript
System.alertError('a', 'The title', 'The message.')

alert ​

javascript
alert(alertOptions: { 
    type?: "alert" | "warning" | "error",
    name?: string,
    title?: string,
    code?: any,
    property?: string,
    propertyValue?: any,
    ruleId?: any,
    priority?: number,
    group?: string,
    entityName?: string,
    message?: string,
    messageError?: string
})

Creates and triggers an alert with the given options object.

Parameters

alertOptions { type?: "alert" | "warning" | "error", name?: string, title?: string, code?: any, property?: string, propertyValue?: any, ruleId?: any, priority?: number, group?: string, entityName?: string, message?: string, messageError?: string}

The object containing the alert options.

Return type

void

Examples

javascript
System.alert({
    type: 'warning',
    name: 'a',
    title: 'The title',
    message: 'The message',
    id: 1001
})

createEntity ​

javascript
createEntity(entityName: string, constructorObject?: { [key: string]: any; })

Creates an entity based on the name. Chain with .to() to cast to the proper Entity type.

Parameters

entityName string

The name of the entity.

constructorObject { [key: string]: any; }

(optional) The object to pass as the parameter to the constructor of the entity.

Return type

RuleSetBaseEntity

Examples

javascript
System.createEntity('Person', { Name: 'Test' }).to(Person)    // => a Person entity

notifyAdmins ​

javascript
notifyAdmins(subject: string, body: string)

Sends a notification email to the admins of the ruleset's organization/tenant. Can be used in case of important system events that need attention.

Parameters

subject string

The subject of the email.

body string

The body of the email.

Return type

void

Examples

javascript
System.notifyAdmins('Issue with updating external system', 'An error occurred: error details here...')

notifySupport ​

javascript
notifySupport(subject: string, body: string)

Sends a notification email to the configured support address. The default support address is support@rulecube.com, but this can be changed via application configuration. Can be used in case of important system events that need attention.

Parameters

subject string

The subject of the email.

body string

The body of the email.

Return type

void

Examples

javascript
System.notifySupport('Issue with updating external system', 'An error occurred: error details here...')

setMetricInput ​

javascript
setMetricInput(metricName: string, metricValue: any)

Sets a metric input by name and value. Will overwrite any existing value by the same name. Note that metrics will need to be enabled in the version settings and execution options for this to work.

Parameters

metricName string

The name of the metric.

metricValue any

The value of the metric.

Return type

void

Examples

javascript
System.setMetricInput('Foo', 1)

setMetricOutput ​

javascript
setMetricOutput(metricName: string, metricValue: any)

Sets a metric output by name and value. Will overwrite any existing value by the same name. Note that metrics will need to be enabled in the version settings and execution options for this to work.

Parameters

metricName string

The name of the metric.

metricValue any

The value of the metric.

Return type

void

Examples

javascript
System.setMetricOutput('Foo', 1)

setNextInput ​

javascript
setNextInput(inputName: string, nextValue: any)

Instructs the system to use a new value for an input in the next run. Used in combination with System.restart().

Parameters

inputName string

The name of the input.

nextValue any

The value of the input in the next run.

Return type

void

Examples

javascript
System.setNextInput('Foo', Foo + 1)

restart ​

javascript
restart()

Instructs the system to run the ruleset again with potentially new input.

Parameters

Return type

void

Examples

javascript
System.restart()

stop ​

javascript
stop(message?: string)

Instructs the system to stop ruleset execution.

Parameters

message string

(optional) The message returned by the ruleset as the reason for stopping execution.

Return type

void

Examples

javascript
System.stop()
System.stop('stop the ruleset')

getCulture ​

javascript
getCulture()

Returns the current culture (language).

Parameters

Return type

string

Examples

javascript
System.getCulture()

isTest ​

javascript
isTest()

Returns whether the system is running in test mode. This is true when a Testcase is executed.

Parameters

Return type

boolean

Examples

javascript
System.isTest()

getTestName ​

javascript
getTestName()

Returns the current Testcase name if any.

Parameters

Return type

string

Examples

javascript
System.getTestName()

getTestCase ​

javascript
getTestCase()

Returns the current Testcase object if any.

Parameters

Return type

{ [key: string]: any; }

Examples

javascript
System.getTestCase()

setStatusCode ​

javascript
setStatusCode(statusCode: number)

Sets the HTTP status code for the ruleset execution response. If not called, the response will use the default status code 200. Status codes must be valid HTTP status codes (100-599).

Parameters

statusCode number

The HTTP status code to set (100-599).

Return type

void

Examples

javascript
System.setStatusCode(201)    // Set response status to 201 (Created)
System.setStatusCode(400)    // Set response status to 400 (Bad Request)
System.setStatusCode(404)    // Set response status to 404 (Not Found)