Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Status
subtletrue
colourYellow
titlesince 1.7.7

Table of Contents

Summary

It is possible to script (using Velocity) a dynamic custom field value to add to issues.  The script is parsed, and whatever value is present in the template after rendering, will be the value applied to the custom field.

Info

For more information on using Velocity see the User Guide here: http://velocity.apache.org/engine/devel/user-guide.html



Note

This guide refers to the legacy custom field default system introduced in version 1.7.7, which is found at the top profile level.  Information on using the new project mapping-level system can be found here: Use Custom Field Defaults.


Example - Setting a Date field 1 day in the future

Create a new Custom Field Default

When the Field Value type is set to Velocity Scripted Value, the "Velocity Context" is expandable, showing the contents of the JEMH Velocity Context, with hyperlinks to online Javadoc.

Showing the velocity context

The (question) icon pops up the velocity context available, including (for now) some static values that would be supplied during real processing

Example content:

Specific Email related values

Status
colourGreen
titlesince 2.4.21

context variable

Data Type

Description

message

javax.mail.Message

the raw message object

subject

java.lang.String

the Subject text

Code Block
$jemhUtils.getCatchEmailAddress().getAddress()

java.lang.String

The Mailbox catchEmailAddress

toAddresses

javax.mail.InternetAddress[]

the to: addressees

ccAddresses

javax.mail.InternetAddress[]

the cc: addressees

bccAddresses

javax.mail.InternetAddress[]

the bcc: addressees (don't expect many here!)

allAddresses

javax.mail.InternetAddress[]

all addressees

body

java.lang.String

the post processed (html > markup) content – (warning) since JEMH 2.7.36 for Jira 7.10.x

jemhUtils

http://ppl-docs.s3-website-us-east-1.amazonaws.com/JEMH/4.1.0/com/javahollic/jira/emh/api/IJEMHVelocityContextUtils.html

JEMH Helper class

Add the Velocity code

Example: Email Address arrays:

Code Block
#foreach ($aCc in $ccAddresses) $aCc.getAddress() : #end

Dates

$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 used with a specific style, based on the date generated from $jemhDateUtils.createDate:

Code Block
languagetext
#set($longVal = $currentMillis.longValue() + 86400000 )
$dateFormatter.withStyle($dateTimeStyle.DATE).format($jemhDateUtils.createDate($longVal))

Preview the output

Press the blue preview button to render the Velocity code in the Preview window.

After Submitting the form, the Custom Field Defaults section view will show the rendered Velocity values as applicable (here showing the next days date, 15/Oct/16 in a valid format):

Now, issues created, will have the Custom Field Test Date set with a dynamically generated value of 29/Mar/15, which is correctly parsed by JIRA and results in issues being created with the appropriate value:

Filter by label (Content by label)
showLabelsfalse
max5
spacesJEMH
sortmodified
showSpacefalse
reversetrue
typepage
cqllabel in ( "customfield" , "default" , "velocity" , "macro" , "dynamic" ) and space = "JEMH" and type = "page"
labelsevent listener jemh issue notification
Page Properties
hiddentrue


Related issues