Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenation of multiple custom fields with separator

Deswik IT April 25, 2019

Hello,

I'm currently using JMWE  "Set Field Value to constant or Groovy expression" to concatenate 4 custom fields with a - separator.  Its working fine but I need to suppress null values and also the separator if the value is null.

The groovy expression is currently:

issue.get("customfield_11200")+" - "+issue.get("customfield_16601")+" - "+issue.get("customfield_16600")+" - "+issue.get("customfield_11206")

This returns VALUE1 - VALUE2 - VALUE3 - VALUE4

If any of the values are null, i want it just to show as VALUE1 - VALUE2 - VALUE4 for example instead of VALUE1 - VALUE2 - null- VALUE4

Can this be done in JMWE?

Many thanks for any help!

 

3 answers

1 accepted

1 vote
Answer accepted
Radhika Vijji _Innovalog_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2019

Hi David,

Much simpler script

[issue.get("customfield_11200"),issue.get("customfield_16601"),issue.get("customfield_16600"),issue.get("customfield_11206")].findAll{
it != null
}.join(" - ")

Regards,

Radhika 

Deswik IT April 26, 2019

Works a charm in the context of JMWE.  Thank you so much

2 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2019

How about an even simpler (and easier perhaps to expand later) script:

def fields = ['11200','16601','16600', '11206']
fields.collect {issue.get("customfield_$it")}.findAll{it != null}.join(' - ')

"

1 vote
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 25, 2019

A simple and rather generic approach:

def arr = []
if (issue.get("customfield_11200"))
  arr += issue.getAsString("customfield_11200")
if (issue.get("customfield_16601"))
  arr += issue.getAsString("customfield_16601")
if (issue.get("customfield_16600"))
  arr += issue.getAsString("customfield_16600")
if (issue.get("customfield_11206"))
  arr += issue.getAsString("customfield_11206")
return arr.join(" - ")

Suggest an answer

Log in or Sign up to answer