Use Script Field Processor

Summary

Here we provide additional information and examples about what can be achieved within the Script Field Processor.

Script Context

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

API

Notes

message.getBody()

Get body content of email. Not available for preprocessing 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

issue

If the email being processed is commenting on an existing issue, then this context will contain the field values for the related issue. Allowing for this data to be used within the Script. Format used is as per the Get Issue response from the Jira REST API.

Note: This is only available within the Script Custom Field default and the Script Field Processor.

For more info about using Issue Data see: https://thepluginpeople.atlassian.net/wiki/spaces/JEMHC/pages/3861676043/Manipulate+Issue+data+in+Scripting+features#Showing-the-JSON-object-Values-and-structure

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. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

RegExp

Searches within string values for matching content.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

Setting Custom Field Values via Script

Within the Script Field Processor values can be set within the script. Values are added to the Result Map in the Script Field Processor which will Overwrite any values already present in the resultMap.

Example

resultMap.set("priority", "High");

Using the Issue Context when commenting

Currently cannot be used at edit time. A email/Test Case will need to be processed to test the script

For more info about using the Issue Data see: https://thepluginpeople.atlassian.net/wiki/spaces/JEMHC/pages/3861676043/Manipulate+Issue+data+in+Scripting+features#Showing-the-JSON-object-Values-and-structure

When Commenting on issues you are able to use the issue to get values from the issue. for example getting the issue Key, Reporter or any Custom Field. Below are some examples on how to extract specific values.

Note: The issue context does not apply when creating an issue. This means that the issue context will return “null”.

Getting the Issue Key

issue.key

Getting the issue ID

issue.id

Getting a Custom Field Value

In order to get the value from a Custom Field you will need to define the Custom Field Id for the relevant field as the field name is not stored within the Issue context. This is to ensure that the value is gathered from the correct Field.

Gathering a System Field Value

For most of the system fields you will be able to define the field name and it will return the value that is set on that field. Below is an example of how to get the name of the Reporter user

Examples scripts

Using Regex to extract a specific value from body and set as a field value

If you want to retrieve specific text from the email body then you can do so by searching the email body with a Regular Expression that will extract the matching values. The below example will search the email body and if found it will then apply the value to the relevant Custom Field.

Example Script:

Example Test Case:

Processing Report:

Here you can see the example mail processing report generated by JEMHC for this Test Case. Within the report it states that a value was matched and that it has applied this value to the example Custom Field.

 

Get a specific header value and then set as a Custom Field value

This example shows how you can extract a value from a specific header and then set this value as a Custom Field value.

Example Script

Test Case

Processing Report

Here you can see the example mail processing report generated by JEMHC for this Test Case. Within the report it states that a value was extracted from the header and that it has applied this value to the example Custom Field.

 

Drop an email if it is sent from a specific sender.

This script will check if the sender matches a specific address and if so then it will drop the email so there is no further processing.

Example Script

Test Case

Processing Report

Here you can see that the email has matched this condition and the email has resulted in being dropped.

Gather all email headers and set as a Custom Field value

This script will gather all of the email headers and set then as a Custom Field value.

Example Script

Test Case

Processing Report

Here you can see that the script has found all of the headers and their values and has set this onto the Paragraph Custom Field.

Dynamically setting a customer request type from X-Priority mail header

We can use

Example Script