Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Extract data from an email using velocity

We're using JEMH, to intercept e-mails from users and extracting data from the e-mail to fill-in certain fields.

One of the things we've configured in JEMH is a script mapping rule, where we want to extract a certain part from an email and map this via Velocity into a custom field, which uses Insight data.

Example: From = role@vessel.domain.name

  • role@: this changes, and must be ignored
  • vessel: this is the part we want to extract
  • domain.name: this never changes, and must be ignored

So in the end we want vessel to remain as a value, so it can be mapped in the insight custom field.

A nice approach would be using regex, but we lack the java expertise to nail this one.

#set($regex = "")

#foreach ($from in $message.getHeader("From"))
$from.replace($regex, "")
#end

 

1 answer

1 accepted

1 vote
Answer accepted

Hi Frederik,

 

For setting a custom field based on a fixed set of email addresses I would use a project mapping domain rule, however it sounds like this sub-domain part is more dynamic/unpredictable.

Two different ways to approach this (choose one):

  1. Velocity driven custom field value. This sounds like what you have attempted so far.
  2. Set the custom field in your scripted mapping rule (this will only set the field on issue creation however)
  3. Set the custom field via Script Field Processor (this separates the setting of the field from the project mapping)

Velocity driven custom field value

A difficult one as we don't currently expose any regex utilities via this velocity script context. However, a (quite hacky) solution:

#foreach ($from in $message.getFrom())
#set ($fromAddress = $from.getAddress())
#if ($fromAddress)
$fromAddress.replaceAll(".+@","").replaceAll("\.domain\.name","")
#break
#end
#end

 

Setting field via script rule (issue creation only)

//you may have a match condition already, if so ignore this block
if (yourmatchcondition){
result.setMatch(true);
}

//this block will set a custom field with a regex extracted value like "vessel"
if (fromAddress && fromAddress.getAddress()){
var regex = /.+@([^\.]+)\.domain\.name/;
var address = fromAddress.getAddress();
var results = address.match(regex);
if (results && results.length > 1){
resultMap.put("your custom field name or id",results[1]);
}
}

 Note that both approaches require you to know how to/be able to set your custom field type with a basic string value.

 

Setting via Script Field Processor

if (fromAddress && fromAddress.getAddress()){
var regex = /.+@([^\.]+)\.domain\.name/;
var address = fromAddress.getAddress();
var results = address.match(regex);
if (results && results.length > 1){
resultMap.put("your custom field name or id",results[1]);
}
}

If you need further help, raise a support request with us (The Plugin People) .

Relevant links:

Hi @Mike using your guidance, we've been successful in implementing a couple off features using the code above.

Thank you very much!

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you