Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

In Closed Beta - not yet publicly available

Summary

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

Script Context

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 has been associated with an existing issue, this contains the issue data. Format is as per the Get Issue response from the Jira REST API. Note: This is only available within the Script Custom Field default.

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");

Example Scripts

Using the Issue Context

The Issue context can only be used when commenting on an issue as this stores the values for the related issue. If creating an issue then “issue” will not return any values and may stop script from functioning.

Getting the Issue Key

issue.key

Getting the issue ID

issue.id

Getting a Custom Field Value

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

issue.fields.customfield_10263

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

issue.fields.reporter.displayName

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

This example shows how Regexp can be used to extract a value from the email body and then set this value within the relevant Custom Field.

var pattern = new RegExp("example:\\s([0-9]+)").exec(message.getBody());
if (pattern !== null)
{
    print("Matched Value: " + pattern[1]);
    setValue(pattern[1]);
}

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 we see that the Custom Field Default successfully sets the value that was found in the email body.

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

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

Example Script

var headerValue = message.getHeader('example');
if (headerValue)
{
    print("Value has been extracted from Header, Setting value: " + headerValue);
    setValue(headerValue);
}
else
{
    print("Header not found");
}

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
Example: Test value
From: ryan@thepluginpeople.com
To: test@test.com
Content-Type: text/plain; charset=UTF-8

This is an example email

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 the Custom Field Default has applied this value.

  • No labels