I’ve been searching for a way to update custom fields in Jira 7+ using Java. The info I found online is either old or not complete. I checked several posts but none of them had the full answer I needed.
I know there are questions about deleting issues, saving values to custom fields, and creating new issues in Jira. But I couldn’t find a clear guide on updating existing custom fields for newer Jira versions.
I found some info about automating field changes and getting previous values of custom fields. There was also something about problems with CustomFieldManager after changing field names. But none of these fully answered my question.
I want to share what I learned but I’m new here and can’t comment on those posts. Does anyone know the current best way to update custom fields in Jira 7 or later versions using Java? Any help would be great!
As someone who’s worked extensively with Jira’s API, I can share what’s worked for me in Jira 7 and above. The key is using the IssueService along with the IssueInputParameters. Here’s a quick rundown:
First, get your issue using the IssueManager. Then, create an IssueInputParameters object and set your custom field value using setCustomFieldValue(). Finally, use the IssueService to perform the update.
One gotcha to watch out for: make sure you have the correct custom field ID. It’s not always obvious, especially if the field name has changed.
Also, don’t forget to handle exceptions properly. Jira’s API can throw various exceptions, and proper error handling will save you headaches down the line.
If you’re using a plugin, consider using the ActiveObjects ORM for better performance and easier data management. It’s been a game-changer for me in larger projects.
Hope this helps point you in the right direction!
hey alex, i’ve dealt with this before. for jira 7+, you wanna use the IssueService and IssueInputParameters. grab the issue with IssueManager, make an IssueInputParameters object, set custom field with setCustomFieldValue(), then update with IssueService. watch out for the right custom field ID tho, its tricky sometimes
For Jira 7 and above, updating custom fields via Java involves using the REST API. You’ll need to create a PUT request to the appropriate endpoint, typically something like ‘/rest/api/2/issue/{issueIdOrKey}’. In your request body, include a JSON object with the custom field updates.
Here’s a basic structure:
String updateJson = "{\n" +
"\"fields\": {\n" +
" \"customfield_10000\": \"New Value\"\n" +
" }\n" +
"}";
// Then use HttpClient or similar to send the PUT request
Remember to handle authentication properly, using methods such as Basic Auth or OAuth, and ensure you have the necessary permissions to modify issues in your Jira instance. Error handling is crucial since Jira’s API can return various status codes and error messages that need to be managed appropriately.