Velocity Script Examples

Summary

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

Storing catch email address information in issues

Velocity reference

 

Description

Velocity reference

 

Description

$catchEmailAddress

https://jemhcloud.thepluginpeople.com/app/static/javadoc/com/thepluginpeople/jemhod/api/IEmailAndPersonal.html

Contains the email address $catchEmailAddress.getEmailAddress() and (optionally) the personal $catchEmailAddress.getPersonal() of the catch email address found in the processed email

$matchingRecipient

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html

Shorthand for $catchEmailAddress.getEmailAddress() (see above).

$matchingCatchEmailAddress

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html

A string representing the configuration responsible for finding the catch email address. Depending on what was configured in the profile, this could be a static address or a regular expression.

When using this custom field value later (e.g. in templates):

Setting a Date field 1 day in the future

To demonstrate this, here is a walk through:

Create a Velocity Custom Field Default

Default custom field values are set in Project Mapping and resolved when an email is processed.

  1. Go to Profile > Project Mapping > Issue > Edit

  2. Under CUSTOM FIELDS DEFAULTS you will see the available custom fields for the project mapping's project.

  3. Find your custom date field, select Velocity and when you want the field to be updated.

  4. Enter the following script: 

     

    $longVal is defined as a variable, (with the value of the current time in milliseconds, plus 24(hours)*60(minutes)*60(seconds)*1000(millis) = 8640000), then the $dateFormatter is in charge of rendering the date generated from $jemhDateUtils.createDate

     

Screen will look like:

After submitting:

Now, issues created or updated, will have the Custom Field Custom Date Picker set with a dynamically generated value of 28/Jan/16, which is parsed and set in the issue.

Setting an email header as a custom field value

Here we show how to extract information from the raw incoming Email and store them in a custom field.

Example Email

For this example we will be extracting the information from the MIME-Version and To: headers along with the custom email header Some-Make-Believe-Header, the following test case will be used:

Email address headers like To:, Cc:, Bcc:, From: should be retrieved using $message.getTo(), $message.getCc(), $message.getBcc(), $message.getRecipients(), $message.getFrom() methods from the IMessage object. These methods know how to handle email and personal addresses returning a list of IEmailAndPersonal objects. These objects have aValue.getEmailAddress() and aValue.getPersonal() methods so you can print the proper information (just just email address or just personal). Alternately full email address can be printed with aValue.toString() fully. E.g.: John Doe <john.doe@company.com>. Custom header can be extracted through $message.getHeader("HEADERNAME").  

Entering the following script in the Custom Fields Defaults section under Profile > Project Mapping > Issue will extract the information from the given email headers:

This scripts comma separates multiples values when rendering the field value. You can revisit $message methods in it javadoc.

Running the test case will result in the information from our desired headers being stored in the custom field Original Message Details.

It is also possible to extract the name of the project mapping that was used to create the issue by using $projectMapping.name.