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

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

0 vote
Jenna Davis Community Champion Oct 16, 2017

Hello, 

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

Jenna Davis

Suggest an answer

Log in or Join to answer
Community showcase
Emilee Spencer
Published 6 hours ago in Marketplace Apps

Marketplace Spotlight: DeepAffects

Hello Atlassian Community! My name is Emilee, and I’m a Product Marketing Manager for the Marketplace team. Starting with this post, I'm kicking off a monthly series of Spotlights to highlight Ma...

30 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot