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

Update value of a custom field when issue is displayed

dbu April 8, 2015

Hi,

I implemented my own custom field type from GenericTextCFType. Now I want to update the value of the custom field every time when the issue view is displayed.

Can i catch something like a "issue display event"? Does anyone got any pointers?

Thanks,

Dominik

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 8, 2015

There is no "display" event, and nothing in "issue view" that could be used as a hook for changing a field.  You'd also potentially impose quite a load by doing this on every view.

Let's step back from the how and look at what you are really trying to achieve?  What should the user get from this field?

dbu April 8, 2015

I have a custom field A with a number. This field is initially filled by a post function, but can be changed by a user.

On the other hand I have a custom field B of my own custom field type like I explained in my question above. The custom field B is composed by custom field A and maybe a custom field A' as well as a constant string.

If the value of field A is changed by a user, field B has to be updated (replace substring) with the value of field A.

I thought it is easier to update the value of B from A every time the issue is displayed.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 8, 2015

Ah, I think I see what you're getting at. But let me repeat it back with an example, so that I can show that I have understood it (or you can tell me where I have not) Working with a single new issue - you have a number field, which is set to 555 by a post-function when the issue is created. You have a second field (We'll call it "Flock size") which shows a value like "We have 555 penguins". If the use now edits the issue, and changes the number from 555 to 333, "Flock size" should automatically change to "We have 333 penguins" There are two ways to achieve this. The first, which is what you've started to think through, is to define the "Flock size" as a standard field and update it when the user changes the number. This works, but you have to do it in a "listener" if you want any change to be picked up (it can also be done in post-functions in workflows, but then you have to disallow edits and plugins like Agile that allow you other routes to edit the number field) The second option (which I would strongly recommend) is to use a derived field. These don't actually store data, they just index it and derive their display from other stored data. I tend to use the Script Runner's "Script fields" to do this because it's the most flexible and powerful, although there are other addons that do it. In my example, the code for script runner would be along the lines of return "We have " + issue.customFieldValue("Flock Size") + "penguins"

dbu April 27, 2015

Hi Nic, thanks for your answer. I found another approach. I can override the getValueFromIssue(CustomField field, Issue issue) method of my customFieldType class. This method seems to be executed every time the issue is displayed. Thanks for your help :)

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 27, 2015

Ouch, that's a recipe for a broken field.

dbu April 27, 2015

Can you be more specific, please?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 27, 2015

Two issues 1. Every visit to your issue will trigger a change to the issue, which is a much heavier load than just reading, as you've got to store the new value and re-index the issue. 2. If two people visit your issue at roughly the same time, the writes could interfere with each other - when JIRA writes to an issue in change mode, it has some simple queuing so that simultaneous updates will effectively be chained one after the other. There's nothing like that on view, so you could end up trashing the data. Neither of those cases are a worry for a small Jira with few users. But you'll get problems as you scale up

Like Gaurav Gupta likes this
dbu April 29, 2015

Sincere thanks, Nic :)

1 vote
Udo Brand
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 8, 2015

Since 5.2 there is a new field "Last Viewed" which can be queried on using JQL. Maybe an Escalation Service from Scriptrunner can be used to update your field.

 

TAGS
AUG Leaders

Atlassian Community Events