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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
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