Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Customfield value (post function)

Omer April 11, 2012

Hi,

I have a textfield customfield named "mytext" whose id is 10001.

I put this customfield in a transition screen. And I changed its value during that transition. I also use a groovy script at the top of post-functions stack at this transition. When I try to get value of this custom field in my script, I come up with two different case;

1- If I use following code to get customefield value, I obtain the original value before transition screen;

CustomField cfA = customFieldManager.getCustomFieldObjectByName("mytext");

log.warn cfA.getValue(issue);

2- With following code, I can get new value that is entered in the transition screen;

CustomField cfA = customFieldManager.getCustomFieldObjectByName("mytext");

log.warn issue.getCustomFieldValue(cfA);

What is exactly going on here? What is the diffenerce between issue.getCustomFieldValue(customfield) and customfield.getValue(issue) methods? Can someone explain me shortly the logic behind?

Thank you in advance.

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Florin Manaila
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.
September 11, 2013

You mentioned that "I also use a groovy script at the top of post-functions stack at this transition". You'll notice that you have a "Save issue and reindex" postfunction in your transition. The idea is that up to that point, the issue object which is passed through the post-functions contains the values entered in the screen (including custom fields) but is not yet saved to the database. So here is the difference between the two: issue.getCustomFieldValue gets the value from the bean, while the custom field manager goes into the DB (which is not yet updated).

You'll also notice this behavior if you get a new instance of the issue by key using the issueManager (which will go to the DB) and compare the standard fields, like description or summary.

Also, if you move the groovy script to the bottom of the stack, both methods should return the same value.

Omer September 12, 2013

Thank you Florin, this was also very useful.

3 votes
Bharadwaj Jannu
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.
September 11, 2013

Hi Omer,

you can check the old and new values for priority as following:

Map<String,ModifiedValue> modifiedValues = issue.getModifiedFields();

if(modifiedValues.containsKey("priority"))

{

System.out.println("If Modified values contain the priority as a key");

ModifiedValue modifiedPrt = modifiedValues.get("priority");

Map oldValue=(Map)modifiedPrt.getOldValue();

Map newValue=(Map)modifiedPrt.getNewValue();

String oldStr=oldValue.get("name").toString();

String newStr=newValue.get("name").toString();

System.out.println(oldStr);

System.out.println(newStr);

}

1 vote
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.
April 11, 2012

> Can someone explain me shortly the logic behind

You would need Atlassian to explain why their APIs behave differently. I'd agree that logically, you'd expect them to behave the same. Just use whichever one gives you the results you need.

Equally, it's the same for updating a custom value.


Omer April 11, 2012

In fact, I need to use both way because I should compare two values (old value and new value of a customfield) in during that transition. Since there is no explanaiton to this behaviour, do you think is there any possiblity for Atlassian to change(or fix) this API in the future? I don't want to build my system over a behaviour that has no decent explanation.

Is there any other way to compare these two values during a transition?

Omer September 11, 2013

Hi Bharadwaj,

This is exactly what I was looking for. Thank you for the reply. Can you convert your comment to an answer for me to be able to approve it.

Thank you indeed

TAGS
AUG Leaders

Atlassian Community Events