It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Need help to set DueDate automatically filled in as 5 days after creation of issue Edited

Dear All,

I am quite new to Jira / Confluence and I am not from development background.

I need to set an Automatic date for Duedate for issues = 5 days after creation of Issue should be DueDate, Should exclude Saturdays and Sundays.

I used a expression / Code from blog as below, but got error messages. To be honest I don't know anything about programming.

Used expression

issue.setDueDate (new Timestamp (cal.getTimeInMillis() + 5 * 1000 * 24 * 60 * 60))

Error message

Unable to resolve class Timestamp @Line 1, column19

I am using Jira v7.13.3


Could you please help and guide

2 answers

1 accepted

1 vote
Answer accepted

Hi there

Do it with a Scriptrunner Postfunction.

  1. Create a scriptrunner postfunction on your create transition, type: custom
  2. Move the Postfunction between the creation step and the re-index step
  3. Add this code
import org.apache.log4j.Level

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

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager()
def creation = issue.getCreated()
def daysToShift = 5

def newDueDate = creation + daysToShift
def dayOfWeek = newDueDate.getDay()

switch (dayOfWeek) {
case 0 : newDueDate = newDueDate + 1 // sunday
log.debug('Adding 1 day to Sunday')
case 6 : newDueDate = newDueDate + 2 // saturday
log.debug('Adding 2 days to Saturday')

issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

log.debug(issue.key+': Due Date has been set to ' + newDueDate)


If it works, you can remove the debug level in production by changing level.DEBUG to level.WARN

@Leonard Chew - Thank you for all the information, I just a beginner - Could you please send some screen shots on steps I need to follow to get this Implemented.

I tried below option but didn't know how to proceed to next step.

I created a transition in workflow as custom


Jira_Custome.jpgI also got below error messages in console


Leonard Chew Community Leader Nov 19, 2019

Hmm, if you lack knowledge of jira-administration basics, it might be wise to persuade your manager to give you an administration course, before you work with scripts.

That said, here are the answer to your questions:

1) General: The script will not work if you paste it in to the script console, as the console does not know on which issue it should run on.
In a postfunction-script, the issue is automatically set to the issue currently being transitionend (created in our case).

2) Do NOT create a new transition. This postfunction should run on the initial "Create"-Transition, which is the line from the circle to the first status. The script automatically sets the due date when an issue is created through this workflow.

Here are some screenshots pasted together to get it to work:



Like Vijaya Kumara likes this

@Leonard Chew  - Thanks a lot for your support, I was able to complete the steps. But I don't see Due Date getting filled in Automatically.

Is there any additional steps I need to complete.


Leonard Chew Community Leader Nov 19, 2019

@Vijaya Kumara  Create an Issue (one that is created by this workflow). The script will be executed and you will see the logs (of the last 15 executions) in the screen you pasted above.

@Leonard Chew - Yes I did create couple of Issues which are using the Workflow where Script was saved using Steps explained by you.

@Leonard Chew - It works, thank you for all suport

Like Leonard Chew likes this

@Leonard Chew  - I have one more request, Now Due Date is created Automatically as 5 days after Issue creation. But this overwrites even If I fill a Due date while creation of Issue, can we set this option only to Issues which are missing Due Date information?.

Leonard Chew Community Leader Nov 19, 2019
if (issue.getDueDate()) {return}

@Leonard Chew - In your program where I should use this expression / Code line

Leonard Chew Community Leader Nov 20, 2019

The code snippet exits the script if due date is set.

If you administer scripts, you will need to be able to read it at least a little bit, so try to figure out where it belongs. Try it out in different places on your testing system. You can use 

log.debug('My Information')

 to help get information.

Like Vijaya Kumara likes this
1 vote

Hi @Vijaya Kumara 

Where exactly did you try the expression that you mentioned above?

You would need an app/add-on like ScriptRunner for doing this.


Hi @Ravi Sagar _Adaptavist_ Yes I have Script Runner add on 

Suggest an answer

Log in or Sign up to answer

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