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

Najmul Khan April 15, 2014

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

0 votes
Najmul Khan April 27, 2014

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

Najmul Khan May 12, 2014

Thanks for your help Fabio,

I got the solution for the same.

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2014

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

Najmul Khan April 21, 2014

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

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2014

please could you provide me the desired format?

Najmul Khan April 21, 2014

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.

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2014

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

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 24, 2014

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

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 15, 2014

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

Najmul Khan April 21, 2014

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

Suggest an answer

Log in or Sign up to answer