Script Rules

Summary

Script rules allow you to create a Custom JavaScript condition that needs to be met for this rule to be matched.

How to enable

  1. Go to Profile > Project Mapping > Rules

  2. Press Create rule to create a new rule

  3. Once created, press the Edit (Cog Icon) Button.

  4. Once in the Rule configuration press the Edit button to configure a Rule.

  5. Now Press Script Configuration

  6. Once press you will now see the configuration for the Script Rule.

  7. Once the Script has been configured, you will then need to go to Rule Configuration and press Active as this will result in the Rule being enabled.

Testing Script Rule

  1. Once the Script has been added, Select a Test Case.

  2. Press Run

  3. Once processed there will be an output of the Results. Allowing you to review if the correct outcome has occurred. For example below.

Results Output

Within the Results output there is 3 sections. These sections are:

  1. Success or Error - This is used to define if the Script was able to be processed correctly or if there was an error with the script. This section also defines if the Test Case was a match or not.

  2. Script Output - This is where the Print values are output, allowing for additional information to be displayed. e.g. using print("Sender is correct: " + message.getHeader('from'));

  3. Script Evaluation Time Metrics - Used to identify how long it took to evaluate the script against the selected Test Case.

How to set Rule as a Match

In order for the Rule to be seen as a match you will need to ensure that the Script defines that there was a match. This is done by using the following line within the Script.

setMatch(true)

For example, the condition below will only set the rule as a match if the sender is “ryan@thepluginpeople.com”.

if (message.getHeader('from') == "ryan@thepluginpeople.com") { print("Sender is correct: " + message.getHeader('from')); setMatch(true); }

Available Script Context

API

Notes

API

Notes

message.getBody()

Get body content of email. Not available for pre-processing script task.

message.getSubject()

Gets the Subject content of email.

message.getAllHeaders()

Get all headers of a message.

message.getHeader(name)

Get value of a message header

Parameters

  • name the name of the header to get

message.setHeader(key, value)

Set the value of a message header

Parameters

  • key (String) the name of the header to set

  • value (String) the value of the header to set

print(str)

Adds output that is recorded during execution and shown in the processing report.

Parameters

  • str (String) the string to be recorded

setOutcome(outcome, reason)

Set the processing outcome of the script

Parameters

  • outcome (String) the outcome type

  • reason (String) the reason for the outcome

Note: outcome must be written in all capitals. Valid outcomes are (IGNORE, FORWARD, DROP)

resultMap

Field processor and Script Rule only. Map - JavaScript | MDN

RegExp

Searches within string values for matching content.RegExp - JavaScript | MDN

setMatch(true)

This is used to define that the script rule is a match. This will result in that Rule and Project being used to process the email

Script Examples

See the following page for some example use cases: Use Script Rule