Copy system field "Due" to CustomField

Jonas Andersson
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.
September 4, 2017

Hi guys,

 

I see hundreds of examples of copying custom fields to other customfields, but how do i copy System field ("Due") to a custom field in all issues matching a JQL?

I am using a snippet found on the community that looks like this:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.util.ImportUtils


def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def issueManager = ComponentAccessor.getIssueManager()
def indexManager = ComponentAccessor.getComponent(IssueIndexManager)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()


def query = jqlQueryParser.parseQuery("project = ATP and due is not EMPTY") // change query to match the issues you want to update
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter()) // get results of query
results.getIssues().each {documentIssue -> // go through each issue
    log.debug(documentIssue.key)
    def issue = issueManager.getIssueObject(documentIssue.id)
    def customFieldManager = ComponentAccessor.getCustomFieldManager()
    def customField = customFieldManager.getCustomFieldObjectByName("Start date");
//    System.out.println(customField)
    customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), documentIssue.key),new DefaultIssueChangeHolder()); // update values
}

List issues = results.getIssues();

for (Issue issue in issues) {
    boolean wasIndexing = ImportUtils.isIndexIssues();
    ImportUtils.setIndexIssues(true);
    indexManager.reIndex(issueManager.getIssue(issue.id));
    ImportUtils.setIndexIssues(wasIndexing);
}

 

 

But i am unable to specify the Due field using this example.. Could someone help me out?

 

3 answers

1 accepted

1 vote
Answer accepted
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.
September 4, 2017

issue.getDueDate returns a "time stamp" object which can go straight into the custom field's modified value.

Jonas Andersson
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.
September 4, 2017

..

Jonas Andersson
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.
September 4, 2017

..

0 votes
Jonas Andersson
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.
September 4, 2017

Needless to say, As usual you kick ass. Got it working just fine! Thanks mate!!

0 votes
Jonas Andersson
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.
September 4, 2017

I should mention that Due field seems to be a string with the text like "2012-01-24" which will go into a custom field that uses date encoding (which follows the exact same format, except for the string vs date type declaration).

Harsh
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.
December 5, 2022

Hey, can you share the final snippet here, I am unable to do the same. I need to copy due date values to custom field.

Lars Swart
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.
January 13, 2023

Hey @Harsh  did you find a working solution. I'm also interested in it.

Harsh
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.
January 17, 2023

Hi @Lars Swart I did using the Automation. If it works for you. 

Suggest an answer

Log in or Sign up to answer