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

miller j October 11, 2017

Hey

I have a challenge, where a transaction, should change a Custom field "Release Date" of the issue based on another custom field "Recurrence" and Due date. 

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

Ex: If due date: 1/16/2016, Recurrence: monthly,

Expected result: Release Date: 2/16/2016

Anyone know a way to solve this?

I found a similar link here, but unable to update custom date field

My Script:

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("Recurrence"));
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Release Date'};
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 "Bi-Weekly":
newDueDate.add(Calendar.WEEK_OF_YEAR, 2)
break
case "Monthly":
newDueDate.add(Calendar.MONTH, 1)
break
case "Weekly":
newDueDate.add(Calendar.WEEK_OF_YEAR, 1)

}

issue.setCustomFieldValue(cf, new DueDate)

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Jenna Davis
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.
October 16, 2017

Hello, 

How are you using this script (as a listener, post function, etc.)? 

Jenna Davis

TAGS
AUG Leaders

Atlassian Community Events