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

3 answers

1 accepted

Accepted Answer
4 votes

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)

 

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)

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.

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

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.

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

It also means that it can't be searched/filtered in JQL using date functions or datepickers.

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

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.

+1 from me for this type of custom field:)

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

0 votes
Tarun Sapra Community Champion Sep 25, 2018

Hello @Дмитрий Соколовский

This feature is now supported out of the box

https://scriptrunner.adaptavist.com/5.4.28/jira/releases/current-release.html

  • [SRJIRA-2668] - Add a Script Fields Template for Dates without timestamps

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Monday in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

406 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you