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,557,473
Community Members
 
Community Events
184
Community Groups

Tracking due date history in a text field using behaviors in Scriptrunner

I am trying to capture the history of due dates in a custom text field, 'Deadline Extension History'. I have set up a ScriptRunner (v 6.24.0) behavior to make the change each time the due date is changed by a user.

----

import java.text.SimpleDateFormat

SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");

def DEH = getFieldByName("Deadline Extension History")
def dueDateField = getFieldById(getFieldChanged()) // Due date has changed
def dueDate = dueDateField.getValue() as Date

// Get the current value of the Deadline Extension History
def selectedOption = DEH.getValue() as String
def valueSet = selectedOption + '\n' + sdf.format(dueDate)
DEH.setFormValue(valueSet)

----

When I make a change to the date, instead of concatenating a single date to the Deadline Extension History it adds several dates:

Expected:
2021/05/10
2021/05/17

Actual:
2021/05/10
2021/05/10
2021/05/10
2021/05/17
2021/05/17

When I modiry the valueSet to either 'selectedOption' or to 'sdf.format(dueDate)', the Deadline Extension History will take on only the value of selectedOption or sdf.format(dueDate), respectively.

Is there a there a better way to set up the behavior to get the expected value? I am able to make this happen on transition, but would prefer to avoid that path.

1 answer

1 accepted

0 votes
Answer accepted
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 08, 2021

Hello @Cory Strope 

Rather than storing every single change in a text field, it would be better to use a read-only/calculated custom field which will directly provide historical dates for duedate field. 

Let me try with a code snippet below. dueDateChanges variable will hold every date values

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.changeHistoryManager
def issueManager = ComponentAccessor.getIssueManager()

def dueDateChanges = []
changeHistoryManager.getChangeItemsForField (issue, "duedate").each {
if (null != it.from) dueDateChanges.add(it.from)
}
if (null != issue.dueDate) dueDateChanges.add (issue.dueDate)

If dueDate changed it will add the "from value" of the change item, then it adds the current value at the end.

You might do the correct date conversions but this code will do your trick after changing a couple of lines for your needs.

I hope it helps

Tuncay

After returning the array, it worked perfect.

Thanks!

Like # people like this
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 10, 2021 • edited

Perfect! I'm glad that it worked.

Like Cory Strope likes this

Hi @Cory Strope 

 

Can you share your code in behaviour? I'm working the same approach. Thanks!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events