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;
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
Thank you for your reply! Is this the approach even if the field is a custom field? I am trying to update the standard due date field on an issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
oh, sorry, that's a system field - you can just use:
issue.setDueDate(today)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tried that but the function setDueDate is not recognized.
I also just tried your last two lines
def today = new java.sql.Timestamp(new Date().getTime())
issue.setDueDate(today)
but it yields the same result.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
make sure you're casting your issue to a MutableIssue type -
try something like this:
import com.atlassian.jira.issue.MutableIssue
...
date dateInTheFuture = c.getTime()
def myIssue = issue as MutableIssue
myIssue.setDueDate(date)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.