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,298,656
Community Members
 
Community Events
165
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

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

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
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

215 views 1 4
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