/
JavaScript examples

JavaScript examples

Summary

Below are some example Velocity Scripts that can be used when setting a Dynamic Custom Field Default.

Script Context

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

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.

print(str)

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

Parameters

  • str (String) the string to be recorded

RegExp

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

setValue(value)

Sets the value for this Custom Field

Setting Custom Field Values via Script

Within the Script Custom Field Default 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.

To set the Custom Field Value you need to ensure that you use setValue(value) within the script to set the extracted value as the

Example

setValue("FieldValue");

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

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.i