reading value as string in groovy

Hi,

I have created a custom issue type where I have to set the summary of that issue type to the custom field value (Email). Here is the code that I am using. The code works fine and sets the summary. I have question about the way I am assinging the value to the summary.

def cf1 = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Email")
def cfVal1 = issue.getCustomFieldValue(cf1).value
cfVal = "" + cfVal1
issue.summary = cfVal

In the above code I have to do ( cfVal = "" + cfVal1 ) to convert the value (cfVal1) to string otherwise it fails when I assign it summary. I tried changing the declaration

def cf1 = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Email")
string cfVal1 = issue.getCustomFieldValue(cf1).value
issue.summary = cfVal1

However that doesn't work. I don't see any errors but the script doesn't work. Any idea why I can't directly assign cfVal1 to Summary ( issue.summary = cfVal1)?

Thanks for your help!

Rama

5 answers

0 vote

You are trying to set the summary of an issue from a custom field value? In what context? In what way doesn't it work?

I created a custom listener to update the summary when issue is created/updated. Below is snippet from code and my listener is working absolutely fine.

def cf1 = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Email")
def cfVal1 = issue.getCustomFieldValue(cf1).value
cfVal = "" + cfVal1
issue.summary = cfVal

My question is why I have have the 3rd line ( cfVal = "" + cfVal1 ) where I am apparently converting the value to string before assigning it to summary.

Why can't I simply do this? (this fails to work)

def cf1 = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Email")
def cfVal1 = issue.getCustomFieldValue(cf1).value
issue.summary = cfVal1

0 vote

What type of field is "Email"?

I am using Regular Expression Custom Field ( Kepler Custom Fields plug-in).I just now also tried with Text Field (single line) and it appears to work this way.


Thanks for your help!

My bad it doesn't work with "Text Field (single line)" either.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

116 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you