JEMHCloud is able to set a custom field value on Create, Comment or Create/Comment. The value can be static pre-defined or dynamic using a Velocity script.  The script is parsed, and whatever value is present in the template after rendering, will be the value applied to the custom field.  

Read more about Velocity in the http://velocity.apache.org/engine/devel/user-guide.html

The Velocity Context

When you create a dynamic Custom Field Default, you can make use of special variables found in the ‘context’, see them through:

Storing catch email address information in issues

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):

#if ( $!context.issue.fields.customfield_13900.value.asText() && $context.issue.fields.customfield_13900.value.asText().equalsIgnoreCase("inboundmailboxaddress@domain.com") )
matched
#else
didnt match
#end

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: 

     

    #set($longVal = $currentMillis.longValue() + 86400000 )  
    $dateFormatter.formatDate($jemhDateUtils.createDate($longVal))

    $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:

MIME-Version: 1.0
Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT)
Date: Sat, 18 Jun 2011 22:42:26 -0700
Message-ID: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com>
Subject: It assistance needed
From: user@example.com
To: mailbox@example.com
Some-Make-Believe-Header: someRandomValue
Content-Type: text/plain; charset=UTF-8

Hello,

I require assistance.

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:

#set ( $mimeVersion = "" )
#foreach ($aValue in $message.getHeader("MIME-Version"))
  #set ( $mimeVersion = "$mimeVersion#if(!$foreach.first), #end$aValue")
#end

#set ( $toAddress = "" )
#foreach ($aValue in $message.getTo())
  #set ( $toAddress = "$toAddress#if(!$foreach.first), #end$aValue.getEmailAddress()")
#end

#set ( $customHeader = "" )
#foreach ($aValue in $message.getHeader("Some-Make-Believe-Header"))
  #set ( $customHeader = "$customHeader#if(!$foreach.first), #end$aValue")
#end

Mime Version = $mimeVersion
Sent To = $toAddress
Some-Make-Believe-Header = $customHeader

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.

Related articles

Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.


Related issues