Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Jira Scriptrunner - REST endpoint that will set an issue property

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?

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 03, 2023

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?

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 06, 2023

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)
/*...*/
}
Like Richard Phillips likes this

Thank you again, now I also understand the queryParams part. Bonus!

Cheers

Suggest an answer

Log in or Sign up to answer