Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Generate generic event every night (with scriptrunner escalation service?) Edited

Dear all,

following issue: We are calculating a custom field using a scriptrunner listener that is triggered to all issue events. The outcome of this script depends (besides other fields) on the current date so we need to run the script every night in order to update the value of the custom field.

We can manually trigger the listener with the scriptrunner built-in scripts "Generate Event" by triggering a generic event. This works very well. Now for the automation I found two ideas in this forum which don't work for us yet:

1) Somehow add the built-in script "Generate Events" to the normal JIRA Services. --> Here I don't know how to add this script in "class". Maybe option 2 is better anyway.
2) Use Scriptrunners Escalation Service. The latter I tried with the code below but unfortunately it always fails (see Screenshot below) and there is no entry in the log.

--> Could someone help us with the code? I am sure the username exists and we are running JIRA 8. 

Thanks a lot!!

2020-01-27 10_17_24-Escalation Services.png

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEventManager
import com.atlassian.jira.event.issue.IssueEventBundleFactory
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.IssueEventBundle

IssueEventManager issueEventM = ComponentAccessor.getIssueEventManager()
IssueEventBundleFactory issueEventFactory = (IssueEventBundleFactory) ComponentAccessor.getComponent(IssueEventBundleFactory.class)

def userManager = ComponentAccessor.getUserManager();
def automationUser = userManager.getUserByName("testuser");

int EVENT_ID = 13

IssueEventBundle eventBundle = issueEventFactory.wrapInBundle(new IssueEvent (issue, null, automationUser, (Long)EVENT_ID, false))

2 answers

0 votes


Before I answer and suggest some options, I'd like to point out a potential danger to your approach. As your project grows, you will get more and more issues that need to be recalculated. At the very least, I'd try to limit this to open issues or something like that.

If the calculated field really needs to be that dynamic and will continue to change on all issues forever, then I'd recommend using a Scripted Field. This means that the field will only be recalculated when viewing or when indexing the field. Unfortunately, that might be a problem if you need this for searching/filtering purposes.

To run a generic script as a service, you just have to add the class "com.onresolve.jira.groovy.GroovyService" give it a friendly name and specify the schedule. After you click add service, you will get another screen where you can input the file path of your script. 
In that script, you could then use JQL to get your issues and iterate over that. 

But the escalation service as you've described should work and give you the ability to manage the JQL directly in the configuration instead of in the code.

When I try your exact code (just changing to a different event id and automation user) I get no errors. 
What errors are you seeing?

Have you checked permissions on the automation user? 

Hi Peter,

thanks for taking the time to reply in detail. I took your advise and limited the escalation service to unresolved issues. 

Unfortunately, I didn't receive any error messages in the log of the escalation service. But I finally found the issue in this way: When I tried not to generate just an event in the escalation service, but instead to run the actual calculation script from the listener I did get error messages in the log. It turned out that the script failed on some issues because some fields that were set to required in the field configuration for this project were not filled.

This in turn happened because we used an upload via XLS lists to upload previously existing issues via the admin interface. If you upload via the admin interface JIRA accepts issues where not all required fields are filled. Apparently it is no problem to run a listener on these not completely filled issues because a listener is not executed as one specific user. In turn, an escalation service is run by one specific user for which JIRA wants all required fields to be filled. 

Of course, the users will fill out the missing fields during the workflow, but we would like to run the script every night already now. So my solution was: Set these fields to "optional" in the field configuration and instead use a behaviour to make these fields required when you create new issues (via a "When" condition and "Workflow Action" on "Create"). 

Hope this may help other users in the future as well :)

Thanks again for your help!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - April 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

316 views 3 20
Read article

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