Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

set jira issue field to the value of a custom field

Janine Roe April 16, 2012

What I need to do is to move a custom value to a jira built in field. So, I need to move the value in the custom field "Conversation" to the jira's Description field.

Where I'm stuck is how to I set (or update) the description field on an Issue? I see no setter for it and doing this way is not letting me as it's a read only field.

Please tell me that there is a way to update a Jira Issue field...

Here is a snippet of my code:

CustomField cfSource = customFieldManager.getCustomFieldObject("customfield_10100");

for(Issue issue in issues)
{
  
    String conversation = issue.getCustomFieldValue(cfSource);
    issue.description = conversation;  
        
}

Thanks in advance.

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Janine Roe April 17, 2012

Hey all -- thanks for your help in pointing me in the right direction. This is my first time delving into the Jira APIs hence first time seeing it all so it's a bit daunting at first. I ended up going with this as a solution (using the IssueService to make the make the updates)

IssueInputParametersImpl inputParameters = new IssueInputParametersImpl();
inputParameters.setDescription(conversation);
inputParameters.addCustomFieldValue(sourceCustomField, "");
validateResults = issueService.validateUpdate(user, issue.getId(), inputParameters);
if (validateResults.isValid()) {

  issueService.update(user, validateResults);

}

In order to make an update to an issue, you have to first test it via validateUpdate and this returns IssueService.UpdateValidationResult which (if it is valid) you pass it into the IssueService.update call.

I'm sure there are other ways to do this, but this worked for me.

0 votes
JamieA
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.
April 17, 2012

You also asked this on the script runner page... There is more than one way of updating an issue. Using the IssueService will result in a changelog and maybe events being fired, which you normally don't want if just doing maintenance.

Here is a way that doesn't create a changelog entry etc:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def componentManager = ComponentManager.getInstance()
def customFieldManager = componentManager.getCustomFieldManager()

def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Name of custom field"}
def changeHolder = new DefaultIssueChangeHolder();
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), "some new value"),changeHolder);

Bah, I didn't read your question properly. Go with Jobin's suggestion.

0 votes
Jobin Kuruvilla [Adaptavist]
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.
April 16, 2012
TAGS
AUG Leaders

Atlassian Community Events