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.
Community moderators have prevented the ability to post new answers.
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.
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);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.