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

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

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
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

335 views 0 1
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