How to set a Date-Time Picker field with value of Current Date Time excluding seconds/milliseconds

SWAPNIL SRIVASTAV September 5, 2019

I want to populate a custom field of type Date-Time picker with Current Date and Time and I want to take the time factor only for hours and minutes i.e. in the format "dd.MM.yy HH:mm" and exclude seconds and milliseconds. The functionality has to implemented a Custom Script Post Function. Kindly suggest the groovy script for same.

1 answer

0 votes
Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 6, 2019

Hello Swapnil,

Per your description, I believe you are needing to add a post function to automatically update a date & time custom field with the current date and time of your instance timezone. Is it correct?

If you re using JIRA Server, I believe you can achieve this need by using Scriptrunner App and use the following Groovy script as a template in your post function:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest

import java.sql.Timestamp

issue.setCustomFieldValue(
        ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("customFieldname")
        , new Timestamp()
)

//only for create transition
/*
ComponentAccessor.getIssueManager().updateIssue(
        ComponentAccessor.getJiraAuthenticationContext().getUser()
        , issue
        , UpdateIssueRequest.builder().sendMail(false).eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).build()
)
*/

If you are using JIRA Cloud, you can use the Update Custom field post function and add the value %%CURRENT_DATETIME%% to it.

P.S: you can use this same post function in JIRA Server too, however, you must install the JIRA Suite Utilities app to use that Post Function.

Let me know if this information helps.

SWAPNIL SRIVASTAV September 12, 2019

Hello @Petter Gonçalves

I am sorry, that did not help as I did not want the seconds and milliseconds part of the current time. 

Following script helped me to resolve the issue.

https://community.atlassian.com/t5/Jira-questions/Store-current-date-in-post-function/qaq-p/244632 .

Thank you for taking out your time and responding.

Regards,

Swapnil Srivastav

Like Gabrielle Walden-Alves likes this
Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 13, 2019

Thank you for sharing the option you found to achieve your need, Swapnil.

Have a nice weekend! :)

Suggest an answer

Log in or Sign up to answer