Using Jira Data Center-
I have created a Refresh button (web item) on the Jira issue details page, when pressed I would like to update a property of the currently displayed issue.
I'm having trouble creating a REST endpoint that will do this.
Use Case: Issue "CLI-888" is being displayed and when I click the Refresh button I would like to create or update a property called "requestRefresh" to have the boolean value True.
That's all, but I feel like I'm going down a rabbit hole with groovy and all of the java and atlassian-specific classes, and I haven't yet figured out how to reference the current issue from within scriptrunner.
Seems like this should be trivial, something like "issue.setProperty("requestRefresh", true).
How should I set this property?
Here is some sample code for setting an issue property value using the IssuePropertyService.
Note that issue properties can only be strings.
import com.atlassian.jira.bc.issue.properties.IssuePropertyService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.entity.property.EntityPropertyService
def issuePropertyService = ComponentAccessor.getComponent(IssuePropertyService)
def currentUser= ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issue=ComponentAccessor.issueManager.getIssueObject('CLI-888')
def input = new EntityPropertyService.PropertyInput(true.toString(), 'requestRefresh')
def validationResult = issuePropertyService.validateSetProperty(currentUser,issue.id, input)
if(!validationResult.valid){
log.error validationResult.errorCollection.errorMessages
return
}
issuePropertyService.setProperty(currentUser, validationResult)
After doing that, you can view the properties using a rest call:
<jira base url>/rest/api/latest/issue/CLI-888/properties
Or using the same API:
issuePropertyService.getProperty(currentUser, issue.id, 'requestRefresh').entityProperty.get().value
Thank you so much for this.
In my question I specified the key 'CLI-888', is there a way to get the key of the currently displayed issue instead of using a fixed string?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In your Web Item fragment, you can include the issue key in the "link" field".
It should look something like this
link:
/rest/scriptrunner/latest/custom/yourEndPoint?issueKey=${issue.key}
Then, in your rest endpoint, simply extract the issue Key from the queryParams
yourEndPoint (httpMethod: 'POST', groups: []) { MultivaluedMap queryParams, String body ->
def issueIssueKey = queryParams.getFirst('issueKey')
def issue=ComponentAccessor.issueManager.getIssueObject(issueIssueKey)
/*...*/
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you again, now I also understand the queryParams part. Bonus!
Cheers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.