Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi All
We want to be able to set the Due Date of tickets in a project to be 14 working days after creation if the field is left blank on creation.
I've been researching this and no one seems to have a definite answer saying , "this is how you do it".
We have script runner installed and the behaviours plugin if it helps.
I would appreciate hearing from someone on this soon.
Kind regards
Adam
Well, with ScriptRunner, there is a really simple definite answer - write a post-function script that sets the due date to (now + 14)
You have to fiddle with milliseconds and timestamps, but...
issue.setDueDate (new Timestamp (cal.getTimeInMillis() + 14 * 1000 * 24 * 60 * 60))
should do it
Hi Nick
Thanks for getting back so quickly it is greatly appreciated.
There are some bits of script runner I'm still getting to grips with.
I dont know how to write a post function script or where post function scripts go?
Sorry.
Adam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Scriptrunner adds "scripted function" as a workflow post-function option. Just add a post function to the workflow and you'll see it on the list. Then skim https://scriptrunner.adaptavist.com/latest/jira/custom-workflow-functions.html (although you might find the examples lower down more useful)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Adam, As Nic said, above link should be a good start to you. You can play with some basic scripts on Dev environment and get used to it. Cheers Chander
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nic Thanks again. I found the post function where i can add a custom scripted function in the workflow of the project i need. I added the script you provided above as a post function of Open transition in the workflow and published it. When i attempt to create a new ticket in the project with this post function script in place nothing happens to the due date field whether the ticket has a blank due date field or not. Do you have any ideas on why this may be the case? Kind regards Adam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've missed imports etc, I just wanted to show the basics of messing with timestamps. Have a look at the application log file ( <jira-home>/logs/atlassian-jira.log ) and see what that says. It'll be java stack traces, so you can ignore most of it, but there should be a clear error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nic Sorry to keep bothering you with this but I am still struggling with this as I am not a coder at all so I dont know what classes I am looking for or need to add where, when or why. Our logs are a mess on our dev system and not sure if they are working correctly or not. Is there any chance you could provide me with the full script that will be required to get this functionality working? Thanks Adam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nic, I'm trying to do this very thing, set the due date to now+5. The full script I have is simple:
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import java.sql.Timestamp;
MutableIssue myIssue = issue;
Calendar cal = Calendar.getInstance();
myIssue.setDueDate(new Timestamp (cal.getTimeInMillis() + 5 * 1000 * 24 * 60 * 60));
It compiles, and runs with no error, but it doesn't actually set the due date. I have it as a post-function on the Create, and it's after "creates issue initially". I'm not even sure what to log to figure out what it isn't doing, but I know I'm missing something obvious. Any ideas? Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, never mind, I moved it up to be the first function and it works beautifully. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please advise us how do you fixed this? I am also in need of set automatic date filed from the created date. How do we do this without scriptrunner.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, the above script worked for me.
Is there a way to calculate based on business days?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Add custom script workflow function:
issue.setDueDate(new Timestamp((new Date() + 14).time))
Make it the first function. I took this from https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/set-issue-attributes.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jamie, Is it possible to set a Due date to Every end of Quarterly.
That is if transition happens today, it should be June 30.
Here it follows:
Any transition in Jan, Feb, Mar = March 30
------------------ Apr, May, Jun = June 30
-------------------Jul, Aug, Sept = Sept 30
Is it possible to give me script during your free time?
Thanks,
Suresh
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.
@Nic Brough (Adaptavist) , @Jamie Echlinis there a way to clear the Due Date field when an issue is cloned? so that the new issue does not have the old issue's Due Date?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A clone is built to copy everything, that's what clone means. There's no easy way to change that to "clear/change arbitrary bits of data".
But, you could write a listener to pick up the event, and modify the issue if it finds it is a clone.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Nic.
I am using the script below to update the Due Date field when and issue is created/cloned that checks for the condition of "clones".
The script runs without any errors but the field stays unchanged. What am I doing wrong? Is there a bettor code/method for this?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.fields.IssueLinksSystemField
import webwork.action.ActionContext
import java.sql.Timestamp
def fieldManager = ComponentAccessor.getFieldManager()
def linksSystemField = fieldManager.getField("issuelinks") as IssueLinksSystemField
def request = ActionContext.getRequest()
if (request) {
def params = request.getParameterMap()
def issueLinkingValue = linksSystemField.getRelevantParams(params) as IssueLinksSystemField.IssueLinkingValue
if ( (issueLinkingValue.linkDescription == "clones" )) {
issue.setDueDate(null)
ComponentAccessor.getIssueManager().updateIssue(issue.getAssignee(), issue, EventDispatchOption.ISSUE_UPDATED, true)
}
}
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using JIRA Cloud and trying to set the deadline outomatically based on other factors. How can I access Timestamp object on the cloud? I had to add several days to a date (custom field), but don't know how to do it without the TimeStamp or Calendar objects. Or is this a way to access them by using Rest API?
Any helps are appreciated! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I use a function like this in plugin code, but should be adaptable to groovy script.
public final static Date rollDate(int datatype, int roll, Date date) {
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(date);
cal.add(datatype, roll);
roundDate(cal);
return cal.getTime();
}
where int datatype is a Calendar type e.g. Calendar.DAY_OF_YEAR and roll is the number of days.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
to add , I quite often put these functions into scipted fields and then use simple field assignments in the workflow.
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.