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.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for sharing the option you found to achieve your need, Swapnil.
Have a nice weekend! :)
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.