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!
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
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(' - ')
"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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(" - ")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.