Updating due-date on workflow transition, with a custom field off set

Mikkel Kragelund Nielsen
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.
August 6, 2012

Hey

I have a challange, where a transaction, should change the due date of the issue. But the change is not static (+5 days, 1 month). the off set is based on a select custom field.

This field have have different periods (weekly, monthly, etc.)

Anyone know a way to solve this?

2 answers

1 accepted

1 vote
Answer accepted
Mikkel Kragelund Nielsen
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.
January 8, 2013

Found that it could be done with a scripted post function, using Script Runner plugin

Pierre Cattin
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.
November 12, 2013

Hi Mikkel,

Did you manage to do it with script runner? Coud you post your script here?

Pierre

Mikkel Kragelund Nielsen
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.
November 13, 2013
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import java.text.SimpleDateFormat
import com.atlassian.jira.issue.comments.CommentManager

Issue issue = issue
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager cfManager = componentManager.getCustomFieldManager()
CommentManager comManager= componentManager.getCommentManager()

String value = issue.getCustomFieldValue(cfManager.getCustomFieldObjectByName("Control Frequency"));
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy/MM/dd")
String originalDueDate = dateFormatter.format(issue.dueDate)

Calendar newDueDate = Calendar.getInstance()
newDueDate.setTimeInMillis(issue.dueDate.time)

boolean update = true

switch (value){
        case "Daily (weekdays)":

            newDueDate.add(Calendar.DAY_OF_YEAR, Calendar.getInstance().get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY ? 3 : 1)
            break

        case "Weekly":
            newDueDate.add(Calendar.WEEK_OF_YEAR, 1)
            break
.
.
.
        case "Every 4 years":
            newDueDate.add(Calendar.YEAR, 4)
            break

        case "Every 5 years":
            newDueDate.add(Calendar.YEAR, 5)
            break

        default:
            update = false
            break
    }

if (update){
    issue.dueDate.time = newDueDate.timeInMillis
    comManager.create(issue, "System", "Executed and Due date changed from " + originalDueDate + " to " + dateFormatter.format(issue.dueDate), false)
    issue.store()
}

Pierre Cattin
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.
November 17, 2013

Thanks a lot!

1 vote
Radu Dumitriu
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.
August 6, 2012

Scripting.

JJupin:

if(customfield_12345 == "1") {

dueDate = currentDate() + "5d";

} else {

dueDate = currentDate() + "4w";

}

http://confluence.kepler-rominfo.com/display/JJUP20/Date+routines

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events