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,293,659
Community Members
 
Community Events
165
Community Groups

Set due date from a Post function using Scriptrunner

Hi!

I am trying to update due date for an issue on a specific transition using post function and Scriptrunner. I have the below code wish is accepted and executed ok. However nothing happens with the Due date field. I am new to this and having a hard time navigating the documentation around it. I have read different posts on the subject and by that collected the code below. Any ideas on what I am doing wrong?

Date date = new Date();
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.YEAR, 1);
c.add(Calendar.MONTH, 0);
c.add(Calendar.DATE, 0);
c.add(Calendar.HOUR, 0);
c.add(Calendar.MINUTE, 0);
c.add(Calendar.SECOND, 0);
Date dateInTheFuture = c.getTime();
issue.fields.duedate = dateInTheFuture;

Transition post functions.jpegCodeWindow.jpeg

1 answer

Here's what I use for this - I'm on Server, so you may have to use the documentation to make a minor tweak if something doesn't work on cloud

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import static java.lang.Math.*
import java.sql.Timestamp

 

// get current issue

def cfManager = ComponentAccessor.customFieldManager

def dateField = cfManager.getCustomFieldObject(12839) //use the ID of your "Due Date" field

 

// get today's date

def today = new java.sql.Timestamp(new Date().getTime())

 

// set value

issue.setCustomFieldValue(dateField, today)

return true

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you