Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Listener for existing issues without opening each issue

Michael Preiss September 17, 2020

Hi,

I have implemented my first listener within an existing project (approx. 400 issues). I want to fire the listener (which calculates couple of custom fields) without the need to open each issue. What is the event to use? I implemented "issue created" and "issue updated" event but this only fires listener for created or updated issues and not all issues in my project, of course. Can anyone help a bloody beginner?

 

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
September 17, 2020

Hi @Michael Preiss welcome at the community.

The idea of listeners is to listen to events raised by SOME object (issue, project, authentication module....), so it will never cover ALL the objects. It also would not be smart because in case of a large number of objects it definitely could have peerformance impact.

So you have to use listener just to be notified that "something happened" and do the rest on your own. If you will describe your use case in detail, we can design the solution together (if it is not some rocky science :))

Michael Preiss September 21, 2020

Hi Martin, many thanks for replying. 

Some more information:

I have a running project with approx. 400 items. Now I need to define a new custom field (a KPI) that needs to be calculated based on input of existing custom field. I have wrote the code for the listener. Now I need kind of a bulk update - so that all custom fields (again approx. 400) are calculated. Otherwise and due to the event trigger "issue updated", i would have to open each single issue manually. So I somehow need to fire the listener for all issues within the project. Can you help?

Michael

Michael Preiss September 21, 2020

Hi, in future the trigger "issues updated" is perfectly fine but I need to do an initial bulk update so that all issues have this calculated field value.

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
September 21, 2020

ok I can see the multiple ways

  1. write a script and run it in ScriptRunenr's Script Console. You would need to add part which selects required issues by JQL and call your function for all the issues
  2. add self transition (transition from Any to Itself) and add your code as postfunction to it. Then you can use Bulk operation Move to invoke this transition which will recalculate value
  3. I'm thinking about simple one and hope it will work. Invoke Edit operation in bulk and updaate some unimportant field. ISSUE_UPDATED should be triggered. If there is no unimportant field you can create one for this purpose and remove it after KPI is calculated.

Let me know if you need additional help :)

Michael Preiss September 21, 2020

Hi, 

what do you mean with "Invoke Edit operation in bulk"? Is this a JIRA function?

Michael

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
September 21, 2020

Hi, yes, you can

  1. Search issues (top bar -> Issues -> Search for issues) + create query which returns issues you want to update
  2. Select Tools in right top corner -> Bulk change all issues
  3. Select listed issues using checkboxes
  4. Select Edit Issues opration in Step 2 of 4 -> Next
  5. Update field in Step 3 of 4
  6. Confirm it in Step 4 of 4

You can check documentation

https://confluence.atlassian.com/jiracoreserver/editing-multiple-issues-at-the-same-time-939937916.html

Michael Preiss September 21, 2020

Hi, that could work. I will check. Many thanks!! Michael

Michael Preiss October 9, 2020

Hi Martin, could you also help me with another issue?

I have two custom fields (both calendar picker) and in one of my listeners I need to identify the months in between those two dates and use it to continue in the listener and to give it back into another custom field. As I am not used to programming, this seems to be a quite complex challenge for me...

With copy&paste from existing listeners, I achieved the following:

def cfEffectiveDate = cfm.getCustomFieldObject("customfield_10048") //First Date
def effectiveDate = cfEffectiveDate.getValue(issue) as Timestamp

def cfEffectiveDateFive = cfm.getCustomFieldObject("customfield_10049") //Second Date
def effectiveDateFive = cfEffectiveDate.getValue(issue) as Timestamp


def effectiveDateYear = effectiveDate.getYear() as Integer
effectiveDateYear -= 120 //NO IDEA WHY THIS IS NEEDED
def effectiveDateMonth = effectiveDate.getMonth() as Integer

def effectiveDateYearFive = effectiveDateFive.getYear() as Integer
effectiveDateYearFive -= 120 //NO IDEA WHY THIS IS NEEDED
def effectiveDateMonthFive = effectiveDateFive.getMonth() as Integer

Now this is where I stand...now I need to define the Duration in months in between and give it back to the custom field "Duration (months)" like this

issue.setCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11776"), duration ? duration : null) // Set cf duration

What I am missing is something in between to calculate duration

def duration = XXXXX as Double

 

Probably there is also a Integer and Double issue in this whole thing which I am not able to solve...

Can you help?

Michael

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events