Copy from text field to date field

Vital Yeutukhovich August 26, 2015

Hello,

I need to copy value from Select list field to Date field. Select list has values like "some_text (06-Dec-2014)". I need to do it in post function

My JIRA version is 4.4.4

Thanks,

Vital

3 answers

1 vote
Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 26, 2015

Update on Transition for JIRA has Update issues post function. You will need use the findReplace substitution variable to get the date text out of the string. That can also be used to make sure the date gets specified in the correct format expected by JIRA for setting the date field. 

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 26, 2015

You can't copy, the data structures are not the same, but that's not a big hurdle, you can parse it.

What are you planning to write this function in?

Azfar Masut
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 14, 2019

Hey @Nic Brough -Adaptavist- ,

Can we parse it using scriptrunner? Do you have an example? To copy from a text field to date field (assuming the text field already in dd/mm/yyyy HH:MM:SS AM/PM format - old admin seems to be passing this date value to jira from API, instead of using date field, he utilized text, so we're cleaning things up). Thanks in advance!

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 15, 2019

Yes, SR can be used to read a field and parse it.

If your text is consistent, it should be quite easy to do.  From memory

import java.text.SimpleDateFormat
import java.util.Date
def oldDateField = customFieldManager.getCustomFieldObjects(issue).find { it.name == "My old date string field" }
Date newDate = new SimpleDateFormat("dd/mm/yyyy HH:MM:SS a").parse(issue.getCustomfieldValue(oldDateField))

Note that I might be missing imports, you'll need to amend field names etc, I've assumed it's in a post-function or something else that has access to the issue object, and my date formatting string may well be wrong.  (My memory is not great at this)

Like Azfar Masut likes this
0 votes
Arthur Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 26, 2015

Hello Vital,

You can use the post-function named "Copy Value From Other Field" from the JIRA Suite Utilities plugin. smile

-- Arthur Gonçalves

Vital Yeutukhovich August 26, 2015

Sorry, but I can't copy text value (I have unnecessary text "some_text (06-Dec-2014)" other than the date) to date field.

Suggest an answer

Log in or Sign up to answer