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

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

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 Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

65 views 0 5
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