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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,062
Community Members
 
Community Events
176
Community Groups

How to store custom project properties in jira using scriptrunner

I'm trying to store custom project properties in Jira server via scriptrunner, but had no success. I found this link that shows how to retrieve a project's properties https://community.atlassian.com/t5/Marketplace-Apps-Integrations/How-to-retrieve-custom-project-properties-in-jira-workflow/qaq-p/1368086

However, I couldn't find any post to store. Any help will be appreciated.

2 answers

1 accepted

0 votes
Answer accepted

Found a solution after tinkering and going through the java docs. Here is a simple solution that got it working. Needs proper error handling and whatnot.

NOTE: the value must be some sort of a map type because it needs to be converted into a JSON format, or else it will not be a valid format after trying to troubleshoot the problem.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.entity.property.EntityProperty
import com.atlassian.jira.entity.property.EntityPropertyOptions
import com.atlassian.jira.entity.property.EntityPropertyService
import com.atlassian.jira.bc.project.property.ProjectPropertyService
import io.atlassian.fugue.Option
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper


class ProjectEntityProperty {
def projectManager
def issueManager
String projectKey
def project
def reporter
ProjectPropertyService pps

ProjectEntityProperty(String projectKey, String userKey) {
this.projectKey = projectKey
projectManager = ComponentAccessor.projectManager
issueManager = ComponentAccessor.issueManager
project = projectManager.getProjectByCurrentKey(this.projectKey)
reporter = ComponentAccessor.userManager.getUserByKey(userKey)
pps = ComponentAccessor.getComponent(ProjectPropertyService.class)
}

def setProperty(String key, Map value) {
def json = new JsonBuilder(value)
def entityPropertyInput = new EntityPropertyService.EntityPropertyInput(json.toString(), key, project.id, project.key)


EntityPropertyOptions entityPropertyOptions = new EntityPropertyOptions(true)
def validatePropertyInput = pps.validatePropertyInput(entityPropertyInput)
def setPropertyValidationResult = pps.validateSetProperty(reporter, project.id, entityPropertyInput, entityPropertyOptions)

if(!setPropertyValidationResult.valid) {
// TODO: throw an exception
// and show something like
// log.warn(setPropertyValidationResult.getProperties())
}

EntityPropertyService.PropertyResult propertyResult = pps.setProperty(reporter, setPropertyValidationResult)
}

def getProperty(String key) {
EntityPropertyService.PropertyResult propertyResult = pps.getProperty(reporter, project.key, key)
Option<EntityProperty> jsonValues = propertyResult.getEntityProperty()
def entityProperty = jsonValues.getOrNull()
JsonSlurper parser = new JsonSlurper()
return parser.parseText(entityProperty.value)
}
}

def ep = new ProjectEntityProperty('SOME_PROJECT_KEY', 'SOME_JIRA_USER_KEY')
String key = 'com.something.example'
ep.setProperty(key, [myData: 'My data'])
return ep.getProperty(key)

 Another solution is to use Active Objects and the solution can be found here https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Active-Objects-in-a-ScriptRunner-plugin/qaq-p/624518

Hi @Mazin 

I'm not sure how to store them via code, however, we use Enhanced Project Properties on our instance and it's working perfectly. And the best thing, it's free :D

We read the properties via code, so that works fine too. And storing goes via the UI which is much more user friendly for non-scripting admins.

It also comes with some additional features such as JQL search.

Hope this helps
Kind regards
Jorden

Hi @Jorden Van Bogaert Thanks for your reply. Just learned I can't use any plugins, sadly.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events