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!
Community moderators have prevented the ability to post new answers.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Depends on where it's being run, as mentioned before.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.