Hello all,
I am looking to create a custom field that will be based on create date plus priority. This field will be mostly used for reporting purposes on columns. I found few examples on creating a listener or adding a workflow create post function. Would it be possible just to go with a custom field, rather then creating something on a workflow.
Example would be:
Create date + 1d if it's a P1, +2d if it's a P2, and +3d if it's a P3.
Any suggestions would be greatly appreciated.
Thanks
Hi DF,
I have attached some example code of how you can use to create a scripted field using a Text Field template that will take the created date and add a number of days to it based on the priority. This field returns a string value of the date which you may find easier to use for reporting purposes.
import com.atlassian.jira.issue.Issue import org.apache.commons.lang.time.DateUtils; import java.text.SimpleDateFormat; import java.util.Date.*; // Get the Jira issue key and its priority Issue issue = issue def Priority = issue.getPriorityObject().getName() def tz = TimeZone.getTimeZone('GMT') SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-YYY"); Date created = issue.getCreated() def strDate = sdf.format(created); // Add values to the current date depending on the priority if(Priority == "P1"){ // Add 1 Day strDate = DateUtils.addDays(created,1).format("dd-MM-YYYY") } else if(Priority == "P2"){ // Add 2 Days strDate = DateUtils.addDays(created,2).format("dd-MM-YYYY") }else if(Priority == "P3"){ // Add 3 Days strDate = DateUtils.addDays(created,3).format("dd-MM-YYYY") } else if(Priority == "P4"){ // Add 4 Days strDate = DateUtils.addDays(created,4).format("dd-MM-YYYY") } else if(Priority == "P5"){ // Add 5 Days strDate = DateUtils.addDays(created,5).format("dd-MM-YYYY") } return strDate
I hope this helps.
Thanks
Kristian
Thanks, works great - Had to make it:
Searcher: Free Text Searcher
Template: Text Field (multi-line)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi DF,
That is the correct searcher and I am glad I could help.
If this answer is useful can you please mark it as accepted so other people with a similar question can easily find this answer in future.
Thanks
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Create a scripted field with the following code:
import org.joda.time.DateTime; if(issue.priorityObject.name.contains("P1")) { return new DateTime(issue.created).plusDays(1).toDate() } if(issue.priorityObject.name.contains("P2")) { return new DateTime(issue.created).plusDays(2).toDate() } if(issue.priorityObject.name.contains("P3")) { return new DateTime(issue.created).plusDays(3).toDate() } issue.created
You should use:
Searcher: Date Time Range picker
Template: Date Time Picker
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, this works as well. One minor change i had to make was changing the template to text field, because using date time picker, wouldn't give me an actual date, but it would say: 2 days, in 4 hours, etc
Making it Text field (multi-line): i got this format
example: Mon Feb 29 18:26:35 EST 2016
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
We have upgraded to JIRA 7 and this custom field is throwing an error now. Do you know why?
See attachmentScreen Shot 2016-06-15 at 2.10.49 PM.png
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the variable "Issue" should be "issue" with lower letter 'i'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Thanks for quick reply - we noticed that mistake and made corrections but now are asking to make more changes. Screen Shot 2016-06-15 at 3.20.54 PM.png
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This was resolved by:
Switching
issue.priorityObject.name.contains ("1-urgent")
to
issue.getPriority ().name == ("1-Urgent")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.