How to transfer the date time field value into the text field in Jira

Hi Team,

I want to transfer the date time field value into the text field,

Please advice me how can I achieve this.

3 answers

This widget could not be displayed.

Hi Najmul,

do you need to do that in a transition? if so, you can setup a scripted post function for that purpose.

Let me know.

Regards,

Fabio

Hi Fabio,

What are the code that I have to write into the Post function. How can I copy the value from date field to simple text field.

Please suggest your answer on the same.

Many thanks in advance!

Regards,

Najmul

This widget could not be displayed.

Hello Najmul,

here your post-function script code :

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import java.text.SimpleDateFormat;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.event.type.EventDispatchOption;

SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
IssueManager issueManager = ComponentAccessor.getIssueManager();
Issue issue  = issue;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField dateField = customFieldManager.getCustomFieldObjectByName("Date Field");
CustomField textField = customFieldManager.getCustomFieldObjectByName("Text Field");
if(issue.getCustomFieldValue(dateField)!=null){
    Date val = (Date)issue.getCustomFieldValue(dateField);
    MutableIssue mIssue = (MutableIssue) issue;
    mIssue.setCustomFieldValue(textField, sdf.format(val));
    issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), mIssue, EventDispatchOption.DO_NOT_DISPATCH, false);
}

Please, update Fields Name and date format at your convenience.

Hope this helps,

Fabio

Hi Fabio,

Its worked fantastically!

but with a problem, Its showing the time which is entering in the database means Singapore time. I want to show the time which is currently in the date field same in the text field.

Please give your valuble answer!

Regards,

Najmul

please could you provide me the desired format?

Hi Fabio,

After creating the ticket the date time field showing me the time as per Indian time zone. As per my knowledge, In database it storing in the form of Singapore time zone.

So when I am trying to run your code it give me the date which is present in the database.

My requirement is that, The date should be come in Inian time zone in the text field.

If you need any more clarification then et me know.

Hi Najmul,

at database level a date is stored as a date (universal) and not as specific timezone. You can define the presentation date format editing the date format into JIRA System Administration panel.

What we need to fix your issue is the desidered date format for your text field :

example yyyy/DD/mm , mm/DD/yyyy, mm-DD-yyyy and so on.

Hope this clarifies,

Fabio

Please, could you mark this answer as accepted if your question has been resolved?

This widget could not be displayed.

Hi Fabio,

Sorry for the late reply, I was on leave.

The code which is provided by you, I just added this code into the post function in the step of create and it is successful. But the same field value is getting chage into the next step, So when I put the same code into the next step post function I am getting the error in log "1 of 2 custom field is already in used"

can you please help me on this!

Regsrds,

Najmul

Thanks for your help Fabio,

I got the solution for the same.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

154 views 1 3
Join discussion

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