Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add a due date to a ticket that wasn't created with one?

Sam
Contributor
December 30, 2019

I'm trying to add a due date to a ticket in Script Runner via a listener and absolutely none of the documentation has been helpful. This all I have so far:

 

import java.sql.Timestamp;

def issue = event.getIssue();
def dueDate = new Date(System.currentTimeMillis() + 7*24*60*60*1000);
//issue.dueDate.setDate(new Date(System.currentTimeMillis() + 7*24*60*60*1000))
issue.dueDate.setTime(System.currentTimeMillis() + 7*24*60*60*1000)

 

The goal is to add a due date that is exactly one week after the ticket was created. Can someone please help?

 

Edit: Also, is there an online textbook or manual where it's explained how to create a custom field? I'm new at this, and I can't find anything like that yet.

1 answer

1 accepted

1 vote
Answer accepted
brbojorque
Community Champion
December 30, 2019

Hi @Sam ,

In your Listener make sure the Event to listen to is Issue Created

Here's the working script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def issueManager = ComponentAccessor.getIssueManager();
def issue = event.getIssue();
issue.setDueDate(new Timestamp((new Date() + 7).time))
def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.ISSUE_UPDATED, false)
Sam
Contributor
December 31, 2019

Hi Bryan,

 

Thank you for the quick response! However, when I copy and paste the code into the listener, I get the error "unable to resolve class Timestamp" at the line 

issue.setDueDate(new Timestamp((new Date() + 7).time))

 Do you know why this might be happening?

brbojorque
Community Champion
December 31, 2019

Hi @Sam ,

Oh right try to import the class at the top.

import java.sql.Timestamp
Like Sam likes this
brbojorque
Community Champion
December 31, 2019

If there are errors, just ignore it and let the script run, i just tested it earlier.

Sam
Contributor
December 31, 2019

Thanks, Bryan! I just tried it, and it worked!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events