A sample code below should update issue fixVersions. If I run it (just without being wrapped in issueUpdateExampleEndpoint function) from ScriptRunner Console or test runner, it works as expected - issue fixVersions are updated properly. If the exactly same code runs within REST Endpoint, validation and update results look OK, no errors, however the fixVersions are not changed.
If I use IssueManager instad of IssueService, it works in both cases, however, I'd like to use a proper way of updating issue (i.e. IssueService), as it doesn't skip validations, indexing etc. like the IssueManager does.
I really don't understand what is the cause of this. It's not about delay - I've checked the issue manually too of course and it has no fixVersions after rest endpoint run
I'm using JIRA v7.13.12 & Scriptrunner 5.6.14
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.project.version.Version
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.servlet.http.HttpServletRequest
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
issueUpdateExampleEndpoint(httpMethod: "POST") { MultivaluedMap queryParams, String requestBody, HttpServletRequest request ->
def issueKey = "TEST-1"
IssueService issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getUserManager().getUserByName("johndoe")
def issue = ComponentAccessor.getIssueService().getIssue(user, issueKey).getIssue()
String responseMsg = "Former versions: ${issue.getFixVersions()}"
Version exampleVersion = ComponentAccessor.getVersionManager().getVersion(15944)
responseMsg += "\nTry to add version: ${exampleVersion} (ID: ${exampleVersion.getId()})"
Long[] versionIds = [exampleVersion.getId()]
IssueInputParameters fieldValueChanges = ComponentAccessor.getIssueService().newIssueInputParameters()
fieldValueChanges = fieldValueChanges.setFixVersionIds(versionIds)
UpdateValidationResult validationResult = issueService.validateUpdate(user, issue.getId(), fieldValueChanges)
responseMsg += "\nIs Validation OK? ${validationResult.isValid()}; Errors: ${validationResult.getErrorCollection().getReasons()}"
IssueResult updateResult = issueService.update(user, validationResult, EventDispatchOption.ISSUE_UPDATED, false)
responseMsg += "\nIs Update OK? ${updateResult.isValid()}; Errors: ${updateResult.getErrorCollection().getReasons()}"
issue = ComponentAccessor.getIssueService().getIssue(user, issueKey).getIssue()
responseMsg += "\nNew set of versions: ${issue.getFixVersions()}"
return Response.ok(responseMsg, MediaType.TEXT_PLAIN_TYPE).build()
}
ScriptRunner Console / Test runner output:
Former versions: []
Try to add version: exampleVersion (ID: 15944)
Is Validation OK? true; Errors: []
Is Update OK? true; Errors: []
New set of versions: [exampleVersion]
ScriptRunner Rest Endpoint output:
Former versions: [] Try to add version: exampleVersion (ID: 15944) Is Validation OK? true; Errors: [] Is Update OK? true; Errors: [] New set of versions: []
Hmm that is very weird indeed.. Just out of curiosity, why are you calling .getIssue() on .getIssue()?
Hello Mathis, thanks for taking a look! And I definitely agree, this is weird :-)
IssueService.getIssue() returns IssueResult, not the Issue instance itself, that is why i call it twice - the second call is IssueResult.getIssue()
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.