Hi
I have created a Date Time Picker script field, Is there anyone can help me remove the Times tamp on my return. Currently field " MM/dd/yyyy hh:mm a (30.04.2018 00:00) " and i will like to get " MM/dd/yyyy (30.04.2018)" this format instead.
Thanks
Hey,
You can customise the date output using a ScriptRunner script field whilst maintaining the current level of search functionality with use of a "Custom" type field.
1. Create a new script field with the following fields set as specified:
Template: "Custom"
Custom Template:
$datePickerFormatter.withStyle($dateTimeStyle.DATE).format($value)
Here are some useful docs regarding custom templates
Inline Script: (This is for testing purposes, you can put whatever script you want here so long as it returns a date)
def date = new Date()
date.previous()
2. Once you click "Add" to add the new field, you need to change the "Searcher" (see here). If you select it as a "Date Time Range picker" then the value will be searchable from within JQL as a date.
NOTE: Script fields are not updated in the Lucene index until either a re-index is run or the individual issue is updated. Script fields are best used for calculating values based on other values in the issue.
I hope this helps!
Steve
Pretty useful, I hope the documentation is updated to include examples like the one which you just shared.
$datePickerFormatter.withStyle($dateTimeStyle.DATE).format($value)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Stephen. We use this exact technique!
The only side-effect to this technique that I can see is that the "dates" now will display in the main issue panel. For some users, this is a pro, others a con.
The following statement needs to be in bold AND red AND larger font AND blink! It's important!
**
NOTE: Script fields are not updated in the Lucene index until either a re-index is run or the individual issue is updated. Script fields are best used for calculating values based on other values in the issue.
**
If your scripted field is getting values from a db or a JQL search or something besides the issue itself (or I think a linked issue), then you're values will be out of synch with your Lucene index. (lesson learned)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @David Sumlin and @Tarun Sapra
I'm glad my answer was enlightening! If you think that others would benefit from my answer, feel free to mark it as accepted so others can more easily benefit from it.
I believe the indexing detail is already specified in the documentation:
It’s also possible to search on these values if you set up one of the four shipped searchers. If you do, the value is calculated and stored in the index at the time that the issue is indexed, eg when it is modified or transitioned, or when you do a full reindex.
You can only reliably use a calculated field to display a value that is based on the issue’s fields, or subtasks' fields, or linked issues. The reason why is because the value in the Lucene index is only updated when the issue is updated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Stephen Cheesley _Adaptavist_
can you tell me, how i can show(custom template) in Dates column?
If i used your custom template, i see value in Details column.
$datePickerFormatter.withStyle($dateTimeStyle.DATE).format($value)
I set the"Date Time Range picker" in property of custom field.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This doesn't work for me using the example exactly as is. The result still includes the timestamp.
Script:
def date = new Date()
date.previous()
Custom formatter:
$datePickerFormatter.withStyle($dateTimeStyle.DATE).format($value)
Using the preview, I get "10/01/2019 11:25 AM"
Versions:
Jira version: v7.13.8
SR version: 5.6.2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @d-sokolovskiy
This feature is now supported out of the box
https://scriptrunner.adaptavist.com/5.4.28/jira/releases/current-release.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello jiradev,
I think your only option is to implement Text script field and manually convert the date into the format you want. You can take a look at how to do it in this answer by Kristian from Adaptavist: https://community.atlassian.com/t5/Jira-questions/Custom-field-based-on-Priority-created-date/qaq-p/75549
Regards,
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Martin,
Thank you for your answer. Everything works perfectly! But the problem is that the script field from the Dates section moved to the Details(text field section) on my screen. Do you have any ideas how can this be fixed?
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hm, you are right. There is no control over where the fields are shown (Date ones on the right in Dates panel, People under People and so on). Making the field of text type unfortunately means it will be showed together with the other text ones. :(
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It also means that it can't be searched/filtered in JQL using date functions or datepickers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's true, I think the only option would be to implement a new custom field which would extend com.atlassian.jira.issue.customfields.impl.DateCFType without any specific implementation. Only view and edit templates for this new custom field would be different - only date part could be edited and displayed. I wasn't able to find any regular documentation about writing new custom field types so it would expect some experience in using JIRA source code to learn how to do it.
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's aggravating since Jira already comes with the functionality we want out of the box for Due date (and I think a couple other fields).
This is completely a display/formatting issue. We understand that there's a date component behind the scenes. We also understand that the date could display different depending on what time zone the user is in.
I'm actually surprised there's not an addon that has this functionality. There's little chance that Atlassian will add this feature, since this has been a desired feature for years.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
+1 from me for this type of custom field:)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does anyone know how to clear the Due Date field value during cloning so that the new ticket does not have the old tickets' Due Date field pre populated while cloning?
I tried a post function but could not get the code right.
Thanks
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.