Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Copy issue description to custom field

Alexander Richter
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.
November 30, 2018

i want to copy the value of issue description to a customfield. I got following code and need to get description as a variable to use it as value for "def modifiedvalue = "some value".

how do i define this?

 

Code:

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

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

def searchQuery = "project = SSPA" // the JQL query you want to use
def customField = "Some Custom Field" // the name of the custom field to change
def modifiedValue = "Some Value" // the new value

def query = jqlQueryParser.parseQuery(searchQuery)

def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

results.getIssues().each {documentIssue ->
    def issue = issueManager.getIssueObject(documentIssue.id)
    def customFieldManager = ComponentAccessor.getCustomFieldManager()
    def modifiedField = customFieldManager.getCustomFieldObjectsByName(customField)[0]
    modifiedField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(modifiedField), modifiedValue),new DefaultIssueChangeHolder())
}

2 answers

1 accepted

0 votes
Answer accepted
Tansu Akdeniz
Community Champion
November 30, 2018

Hi @Alexander Richter,

Please try this one;

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.event.type.EventDispatchOption;

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

def searchQuery = "project = SSPA" // the JQL query you want to use
def customField = "customfield_xxxxx" // the id of the custom field to change
def fieldCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(customField);

def query = jqlQueryParser.parseQuery(searchQuery)
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

results.getIssues().each {documentIssue ->
def jqlIssue = issueManager.getIssueObject(documentIssue.id)
log.error("Issue: " +jqlIssue.key)
jqlIssue.setCustomFieldValue(fieldCF,jqlIssue.getDescription())
issueManager.updateIssue(user, jqlIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
}

Tansu 

Alexander Richter
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.
November 30, 2018

Hi Tansu,

it works, thank you very much :)

Alex

Tansu Akdeniz
Community Champion
November 30, 2018

You are welcome :)

0 votes
Fazila Ashraf
Community Champion
November 30, 2018

Hi @Alexander Richter

If your question is about how to get an issue's description value in groovy, you can use 

 

def descValue = issue.getDescription()

Suggest an answer

Log in or Sign up to answer