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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,123
Community Members
 
Community Events
184
Community Groups

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 {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

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.
Dec 06, 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.
Jan 06, 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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events