Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Customfield value (post function)

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

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.

Thank you Florin, this was also very useful.

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);

}

> 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.


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?

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

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you