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.