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

How to update jira issue in plugin module?

Roman Samorodov
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 12, 2017

Hi!

I want to change subtask field using the same task field. And of course it should be saved in database

I already know how to find issues and get values from it. Surprisingly there is no easy way to save only one field value into issue.

Does anybody know any easy way to perform it? Any suitable examples of code are appreciated!

2 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
Roman Samorodov
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 16, 2017

Here is my code! Just use it!

CustomField csUserField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(fieldName);
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.addCustomFieldValue(csUserField.getId(), value_string);
issueInputParameters.setSkipScreenCheck(true);
issueInputParameters.setRetainExistingValuesWhenParameterNotProvided(true, true);
UpdateValidationResult updateValidationResult = issueService.validateUpdate(user, issue.getId(), issueInputParameters);	
if (updateValidationResult.isValid())
{
    IssueResult updateResult = issueService.update(user, updateValidationResult);
    if (!updateResult.isValid())
    {
    	log.warn("ISSUE has NOT been updated. Errors: {}\n", updateResult.getErrorCollection().toString());
    }
    else
    {
    	log.warn("ISSUE has been updated.\n");
    }
}
else
{
	log.warn("ISSUE has NOT been updated. Errors: {}\n", updateResult.getErrorCollection().toString());
}

You can change other fields of issues, for more information IssueInputParameters.

Scheibli Márk July 14, 2017

Can I ask that how could i get the "issue" parameter from here? Its really not clear for me, what is that parameter and how can get it.

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.
July 14, 2017

Depends on where it's being run, as mentioned before.

Scheibli Márk July 15, 2017

And if i want to set the value of one of the create issue's field, then what is the issue attribute? Or it isn't possible this way.

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.
July 15, 2017

It is possible, in most case, but it depends on where the code is being run.  That determines how you can get to the issue.

Scheibli Márk July 18, 2017

Is there any possible way to delete the values for example from a label? Is there any method? I have not found a good one for me and at the moment i can update values but i have to delete as well. Can u help me, please?

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.
July 18, 2017

To delete labels, you'd read the current list attached to the issue into a list, scan for and remove the unwanted ones, then write the list back to the issue if you found any to be removed.

Scheibli Márk July 18, 2017

And can you give mi the Jira Server API interface should i use for this? Or it's the same issueService.update() method i can see at the top? Because if i use update() method, it is just adding the options to the others and don't change the other values.

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.
January 13, 2017

The exact method depends on where your code is running (add-ons can provide many different routes - post-functions, listeners, fields etc), but generally you'll use the issueService and/or changeHolder.  Very very roughly, they take an issue object with the current values, let you change what you want and update the actual issue from it.  The change operation is the same process whether you're changing one field or all of them.

Roman Samorodov
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.
March 2, 2017

Thanks for your comment!

I run this code in my own plugin module that implement event listener.

When I was writing my plugin I couldnt find any complete piece of code that really works performing changing issues. Only advices or single lines of code. Complete pieces of code are very helpful for developers who have as little experience as I smile

TAGS
AUG Leaders

Atlassian Community Events