Hi,
I'm attempting to automatically add a "Due Date" to imcoming emails into jira via an external email client such as Outlook.
So i've used:
Copy Value From Field to Field: Copies the value(s) of one field to another field. Can copy the value of the field before it was changed on the transition's screen.'
Add i've added it to the "Create" state in the workflow:
Add a new post function to the unconditional result of the transition.
Which seems to work, However When I Create the issue via the "Create issue" button internally this still overides any due date selected and uses the create date.
How can i do it so that if for instance if due date is field is empty to then use "Copy Value From Field to Field" otherwise if due date is not empty to continue?
We have an problem with emails/issues that come into jira without a due date and then it does not get worked on. so we need to enforce a due date if not added?
any suggestions?
*PS. Hope it makes sense?
Community moderators have prevented the ability to post new answers.
You can use the Script Runner plugin and a scripted post function, which tests if the due date is set and if not updates it with the created date. Maybe a good start is the example postfunction here.
Henning
Hi, I was thinking that route, but i'm not too sure how?
These are my only options when writing a post-function:
Built-in Scripts Adds a comment to all blocked issues when this issue is transitioned.
Useful for alerting participants of other issues that a blocker is resolved, etc.
This function should be put on the Resolve transition (or similar).Send a custom email
Send an email based on the provided template if conditions are metFast-track transition an issue
If the condition is met, automatically transition this issue to another statusClones an issue and links.
Clones this issue to another issue, optioninally in another project, and optionally a different issue type.Transition parent when all subtasks are resolved
This will do the given action on the parent when all sub-tasks are resolvedCreate a sub-task.
Create a sub-task. Will optionally reopen a matching sub-task.Fires an event when condition is true
Fires an event that can be picked up by a notification scheme, in order to send mail only under certain conditions, eg Priority is BlockerAdds the current user as a watcher
Adds the user performing the action as a watcher, if condition appliesor Script file path:
Would is have to write a separate file an use: Script file path?
What format would i save it?
Could you elborate for me?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do i need a special program to write .groovy files?
Thanks for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The script is something like this (not tested by me, I'm not sure if you get the due date in the issue, maybe it depends on the position of the postfunction in the postfunction list)
import com.atlassian.jira.issue.MutableIssue MutableIssue mIssue = issue if (!mIssue.getDueDate()) { mIssue.setDueDate(mIssue.created) }
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Save it as SetDueDate.groovy on the server and provide the path while adding it to the workflow.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A text editor is fine.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I ran the above script in the script runner's condition tester, it failed? I'm going to need some help with groovy scripts as i'm not too fluent in groovy?
how is "Mutable" relevant?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
An issue object represents an issue. A mutable-issue object represents an issue that is in the process of changing - you've got access to the current issue data and what the users may have changed on it. So if you're changing an issue, you work with a mutable issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What kind of error did you get in the condition tester? I think within the condition tester you don't have a mutable issue as issue and the changes will not be saved. Here you could only test conditions for other scripts, which do tests on current issue data. If you use the script as a scripted postfunction, the mutable issue is saved by the system after the script changed it.
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Strangely no error just The result evaluated to false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, that's the value of the last operation of the script. If you wan't to try it within the condition tester you have to modify the script to this
import com.atlassian.jira.issue.MutableIssue MutableIssue mIssue = issue if (!mIssue.getDueDate()) { mIssue.setDueDate(mIssue.created) } mIssue.store()
This saves this issue object, but you don't need this for the post function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi guys, as per this issue: https://answers.atlassian.com/questions/195955/automatic-due-date-by-issue-type-when-creating-ticket?page=1#260376
I have managed to get Automated due date, How ever is there any way to exclude weekends? Or for instance if the due date falls on a weekend that it gets changed to the very next monday?
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.
The dates you get in the scripts are Java Timestamps. You could do whatever you need with them before you write them to the issue. For checking Java Timestamps for weekends etc. a Google search should help. A good starting point should be Calendar.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning, I'm not sure how well versed you are on Java Timestamps, but I've come up with this and it doesn't seem to be working?
import org.apache.log4j.Category import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.CustomFieldType import com.atlassian.jira.issue.fields.CustomField import java.sql.Timestamp; Timestamp mydueDate; int days = 5; int dayOfWeek; MutableIssue myIssue = issue; Calendar cal = Calendar.getInstance(); do { // add due date one day into the future mydueDate = new Timestamp(cal.getTimeInMillis() + days*1000*24*60*60); cal.setTimeInMillis(mydueDate.getTime()); dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); //System.out.println(String.format("Day of week is %d / days: %d", dayOfWeek, days)); days = days + 1; } while ((dayOfWeek == Calendar.SATURDAY) || (dayOfWeek == Calendar.SUNDAY)); myIssue.setDueDate(mydueDate); log.warn ("script setduedate is running...and mydueDate is:" + mydueDate)
Any suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mmmh. Do {} while doesn't exist in Groovy... Didn't you get an error message in the log?
Try this
import com.atlassian.jira.issue.MutableIssue import java.sql.Timestamp; MutableIssue myIssue = issue; Calendar duedate = Calendar.getInstance() duedate.add(Calendar.DATE,1) while ([Calendar.SATURDAY, Calendar.SUNDAY].contains(duedate.get(Calendar.DAY_OF_WEEK))) { duedate.add(Calendar.DATE,1) } def dueTimestamp = new Timestamp(duedate.getTimeInMillis()) myIssue.setDueDate(dueTimestamp) log.warn ("script setduedate is running...and dueTimestamp is:" + dueTimestamp)
I didn't test it, but I think it's a good start :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning,
I did see that only after I posted. However I did manage to come right with this code... So far seems to be working:
import org.apache.log4j.Category import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.CustomFieldType import com.atlassian.jira.issue.fields.CustomField import java.sql.Timestamp; int days = 8; int dayOfWeek = 0; Date today = new Date(); MutableIssue myIssue = issue Calendar dueDate = Calendar.getInstance(); while ((dayOfWeek == 0) || (dayOfWeek == Calendar.SATURDAY) || (dayOfWeek == Calendar.SUNDAY)) { dueDate.setTimeInMillis(today.getTime() + days*1000*24*60*60); dayOfWeek = dueDate.get(Calendar.DAY_OF_WEEK); days = days + 1; } System.out.println("script setduedate is running...and mydueDate is:" + dueDate.getTime()); myIssue.setDueDate(new Timestamp(dueDate.getTime().getTime()));
Thanks for all your halp and knowledge by the way
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.
Thanks Henning, I will have a look into this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can't. The functions you've found are flat and unconditional - they do what they say on the tin and "copy value from field to field" without any form of checking of pre-existing data.
You'll need to write a function which duplicates these, but includes some extra code to say "already got a date, so I won't override it"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Write your own plugin that provides a post-function that includes the conditional code you need.
Henning has pointed at the script runner (that saves you having to write an entire plugin)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you elaborate on
You'll need to write a function which duplicates these, but includes some extra code to say "already got a date, so I won't override it"
Write a function, how?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So Hennings approach is good?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, it does what we said - enables a post function that creates the "if" you need.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Using Henning's code didn't quite work for me. It was overwriting customer set due dates. I made a small change, added an if statement, and now it's working for me. I also changed mine to set the due date to two days after the issue is created.
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp;
MutableIssue myIssue = issue;
Calendar duedate = Calendar.getInstance()
if (!myIssue.getDueDate()) {
duedate.add(Calendar.DATE,2)
while ([Calendar.SATURDAY, Calendar.SUNDAY].contains(duedate.get(Calendar.DAY_OF_WEEK))) {
duedate.add(Calendar.DATE,1)
}
def dueTimestamp = new Timestamp(duedate.getTimeInMillis())
myIssue.setDueDate(dueTimestamp)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I often see solutions that use 'code', but I never know where I should put this information.
I want to be able to map my Fix Version Release date into my Due Date for a card.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.