Copying Deadlines from SLA Powerbox to custom field

We are using SLA Powerbox for managing our SLA agreements. By ordering our issues based on the SLADate (Deadline) we want to establish the backlog of our issues. 

However, sometimes it is required to fix issues earlier (manually setting the deadline). Since SLA Powerbox currently does not support the manual setting of the deadline, we try to copy the deadline to a normal date field. This is done in a custom listener listening on "Issue updated" events.

This is where things get interesting:

When updating the issue normally (not triggering a change of the SLA goal) everything works as expected.

However when the update recalculates the SLA goal, the code below takes the old deadline instead of the new one.

The code looks as follows:

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def delivery_date_READ = customFieldManager.getCustomFieldObjects(issue).find { == 'SLAPOWERBOX Deadline'}

def delivery_date_write = customFieldManager.getCustomFieldObjects(issue).find { == 'Manual Deadline'}

def new_value = issue.getCustomFieldValue(delivery_date_READ)
def old_value = issue.getCustomFieldValue(delivery_date_write)

def modified_deliver_value = new ModifiedValue(old_value, new_value)
def changer_one = new DefaultIssueChangeHolder()

delivery_date_write.updateValue(null, issue, modified_deliver_value, changer_one)

 It seems that the code in the listener is executed before the SLA goal is calculated. Is there any way to postpone the execution?

2 answers

Hi Christian.

We do not officially support interaction with third party addons, since they work in a very different way than we do.

However, it seems like your issue doesn't have do with this.

when you do this:

def new_value = issue.getCustomFieldValue(delivery_date_READ)
def old_value = issue.getCustomFieldValue(delivery_date_write)

You are taking values from the issue object that hasn't been indexed yet,(It is being indexed at that moment in time, and that is why you are capturing the event), I believe. That is causing you to get the old data instead of the new one.

In order to get the new data, you need to access the information of the change in the params. To do so, check the first line.

def change = changeItems.find {it.field == "Name of custom field"}
if (change) {
 def oldValue = change.oldstring
 def newValue = change.newstring

This will check that your custom field has changed an it will have the new value in that change.newstring.

Hope this helped, if you need anymore help, please do say, and if this helped, please accept and upvote my answer so that other users can benefit from this question.




SLA PowerBox uses listeners to recalculate sla fields so it's possible that SLA listener starts after Script Runner's one.

There are a couple of ways to set deadline manually, so please raise a support request on CoreSoft Labs service desk system and we'll provide you support.



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

893 views 3 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you