Copying Deadlines from SLA Powerbox to custom field

Christian Körner November 27, 2017

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 {it.name == 'SLAPOWERBOX Deadline'}

def delivery_date_write = customFieldManager.getCustomFieldObjects(issue).find {it.name == '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

Suggest an answer

Log in or Sign up to answer
1 vote
Daniel Yelamos [Adaptavist]
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.
December 6, 2017

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.

Cheers!

Dyelamos

0 votes
Robert Dzido
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.
January 6, 2018

Christian,

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.

Cheers,

Robert

TAGS
AUG Leaders

Atlassian Community Events