JIRA 6.3.13
ScriptRunner 4.1.3.4
I have a script which is running on a transition in our Helpdesk (HD) project that tries to transition the status of a linked issue in our Windows Server Support Team (WSST) project. The script should be performing the transition as the user "jirabot" which is a non-person user in the automaticservices group, which has wide permissions to do pretty much anything in every project.
When the user cgreco9 transitions the HD ticket which fires off the ScriptRunner script, I get an error in the logs saying that the user cgreco9 doesn't have permission to transition the WSST ticket. This is true, she doesn't have permission, but the transition should be performed by jirabot, not the user. Why and how can I fix this?
Here is my script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
def issueService = ComponentAccessor.getIssueService()
def linkType = ["Escalated"]
// 6.x validateTransition wants a User, so we have to use .getDirectoryUser()
// 7.x validateTransition wants an ApplicationUser, so remove the .getDirectoryUser() after we upgrade
//def transUsers = ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser()
def transUsers = ComponentAccessor.getUserManager().getUserByName("jirabot").getDirectoryUser()
def linkMgr = ComponentAccessor.getIssueLinkManager()
// Look through the issue links
// If we're starting on an issue with a link that says "escalated to", then use:
// getInwardLinks(issue.id)
// getSourceObject()
// If we're starting on an issue with a link that says "escalated from", then use:
// getOutwardLinks(issue.id)
// getDestinationObject()
for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
def linkedIssue = link.getSourceObject()
// Does the name of the link match "Escalated" ?
if (linkType.contains(link.issueLinkType.name)) {
def destStatusObject = linkedIssue.getStatusObject()
// Is the status of the linked issue "Signs Needed" ?
if (destStatusObject.name == "Signs Needed") {
// Prepare our input for the transition
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
setComment("CCPS has posted signs. Cameras can now be activated.")
//setSkipScreenCheck(true)
}
// Validate transitioning the linked issue to "Signs Needed"
def validationResult = issueService.validateTransition(transUsers, linkedIssue.id, 61, issueInputParameters)
if (validationResult.isValid()) {
// Perform the transition
def issueResult = issueService.transition(transUsers, validationResult)
if (! issueResult.isValid()) {
log.warn("Failed to transition task ${linkedIssue.key}, errors: ${issueResult.errorCollection}")
}
} else {
log.warn("Could not transition task ${linkedIssue.key}, errors: ${validationResult.errorCollection}")
}
} else {
log.warn("Skipping link: ${link.issueLinkType.name} ${linkedIssue.key} ${destStatusObject.name} (wrong status)")
}
} else {
log.warn("Skipping link: ${link.issueLinkType.name} ${linkedIssue.key} (wrong type)")
}
}
And here is the error:
2017-01-31 11:31:16,426 http-bio-8080-exec-59 WARN cgreco9 691x1295970x1 1aed2mk 172.18.58.5 /secure/CommentAssignIs
sue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Could not transition task WSST-7603, errors: Errors: {}
Error Messages: [Christine Greco, you do not have the permission to comment on this issue.]