JavaScript examples
Summary
Below are some example Velocity Scripts that can be used when setting a Dynamic Custom Field Default.
Script Context
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
|
| 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. |
| Adds output that is recorded during execution and shown in the processing report. Parameters
|
| Searches within string values for matching content.RegExp - JavaScript | MDN |
| 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