Below, we provide additional information and examples about what can be achieved within a Script Rule.
This table shows a subset of what is available, we host our own utility class javadoc, e.g. http://ppl-docs.s3-website-us-east-1.amazonaws.com/JEMH/4.1.33/com/javahollic/jira/emh/api/IJEMHVelocityContextUtils.html
API | Notes |
---|---|
| Get body content of email. Not available for preprocessing task. |
| Gets the Subject content of email. |
| Get all headers of a message. |
| Get value of a message header Parameters
|
| Set the value of a message header Parameters
|
| Adds output that is recorded during execution and shown in the processing report. Parameters
|
| Set the processing outcome of the script Parameters
Note: |
| Field processor and Script Rule only. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map |
| Searches within string values for matching content.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp |
| 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. |
This script uses a Regular Expression to match a specific word within the body. If found then it will match on this rule and will add the value to a specific Custom Field.
Example Script:
var pattern = new RegExp("example:\\s([0-9]+)").exec(message.getBody()); if (pattern !== null) { print("Matched Value: " + pattern[1]); resultMap.set("example", pattern[1]); setMatch(true); } |
Example Test Case:
MIME-Version: 1.0 Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT) Date: Sun, 19 Jun 2011 17:42:26 +1200 Subject: This is the email subject From: ryan@thepluginpeople.com To: test@test.com Content-Type: text/plain; charset=UTF-8 This is an example email example: 100 |
Processing Report:
Here you can see the example mail processing report generated by JEMHC for this Test Case. Within the report it states that the script rule was matched and that a value was matched and has applied this value to the example Custom Field.
This script gathers the from header and then checks if the sender address matches and if so then the rule will be set as a match.
Example
var senderAddress = message.getHeader('from'); if (senderAddress == "ryan@thepluginpeople.com") { setMatch(true); } |
Test Case
MIME-Version: 1.0 Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT) Date: Sun, 19 Jun 2011 17:42:26 +1200 Subject: This is the email subject From: ryan@thepluginpeople.com To: test@test.com Content-Type: text/plain; charset=UTF-8 This is an example email example: 100 |
Processing Report
This script will gather a specific header and if it contains a specific value then the rule will be set as a match.
Example
var headerValue = message.getHeader('example'); if (headerValue == "Example Value") { setMatch(true); } |
Test Case
MIME-Version: 1.0 Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT) Date: Sun, 19 Jun 2011 17:42:26 +1200 Subject: This is the email subject From: ryan@thepluginpeople.com To: test@test.com Example: Example Value Content-Type: text/plain; charset=UTF-8 This is an example email example: 100 |
Processing Report
Note regarding retrieving specific headers:
|
To reject using script rule, you can define setOutcome
, specifying the outcome
and reason
for the outcome.
Current available outcomes are: IGNORE
, DROP
, and FORWARD
Example
setOutcome('IGNORE','Reason for reject outcome goes here') |
As with the Script Field Processor, the Script Rule also makes use of the resultMap object to allow Custom Field Values to be updated. Values are added to the Result Map in the Script rule which will Overwrite any values already present in the resultMap.
Example
resultMap.set("priority", "High"); |