reading value as string in groovy

RamamandA July 29, 2014

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

1 vote
RamamandA July 29, 2014

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 votes
RamamandA July 29, 2014

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

0 votes
RamamandA July 29, 2014

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!

0 votes
JamieA
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.
July 29, 2014

What type of field is "Email"?

0 votes
JamieA
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.
July 29, 2014

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?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events