How can I create a new property to an object?
Asked by Rafael Costa:

I would like add a property called "owner" to some groups. Is it possible?

![2022-03-02_16-06-25.png](https://community.atlassian.com/t5/image/serverpage/image-id/186120i8A10F37FFE7A33CF/image-size/large?v=v2&px=999 "2022-03-02_16-06-25.png")


Answers:
author: Peter-Dave Sheehan
body: I think there are 3 choices.

I'm most familiar with [OfBizPropertyUtils](https://docs.atlassian.com/software/jira/docs/api/8.13.15/com/atlassian/core/ofbiz/util/OFBizPropertyUtils.html): that stores values in propertyentry and propertytext tables (at least for jira):

```
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.core.ofbiz.util.OFBizPropertyUtils
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper

def GROUP_EDITOR_PROPERTY = 'com.acme.jira.group-editor'
def properties = OFBizPropertyUtils.getCachingPropertySet(GROUP_EDITOR_PROPERTY, 1)
def group = ComponentAccessor.groupManager.getGroup('bamboo-users')

if (properties.exists(group.name)) {
    def editorsJson = properties.getText(group.name)
    def editorUserNames = new JsonSlurper().parseText(editorsJson)
    return editorUserNames.collect { ComponentAccessor.userManager.getUserByName(it as String) }
} else {
    def editor = ComponentAccessor.userManager.getUserByName('editorName')
    def editorJson = new JsonBuilder([editor]).toString()
    properties.setText(group.name, editorJson)
}
```

But I think the [JsonEntityPropertyManager](https://docs.atlassian.com/software/jira/docs/api/8.13.15/com/atlassian/jira/entity/property/JsonEntityPropertyManager.html) may also do the trick but I haven't tried to use it with custom entities or properties. This would store data in entiry_property

And finally, there is the CrowdService that stores data in cwd_group_attributes

```
import com.atlassian.jira.component.ComponentAccessor

def GROUP_EDITOR_PROPERTY = 'com.acme.jira.group-editor'
def cs = ComponentAccessor.crowdService

def group = cs.getGroupWithAttributes('bamboo-users')

cs.setGroupAttribute(group, GROUP_EDITOR_PROPERTY, 'editorName')
//reload the group
group = cs.getGroupWithAttributes(group.name)
group.getValue(GROUP_EDITOR_PROPERTY)
```

comments: author: Rafael Costa
body: greaat! I can set a property with 2nd way!!!

but now how can I know all properties that I can define and how get all this properties?


author: Peter-Dave Sheehan
body: I forgot to include the link to the [GroupWithAttributes](http://More%20details here:?https://docs.atlassian.com/atlassian-crowd/4.4.0/com/atlassian/crowd/embedded/api/GroupWithAttributes.html) Javadoc.

In all cases I shared, you define the properties/attributes you want to store yourself.

These are completely custom. I find the best way to explore what properties have already been defined by the system or by other plugins is to use the database.

In the case of GroupWithAttributes, in my environment, there was nothing until I added my own property. There is a similar UserWithAttribute that typically holds several attributes stored by Jira (like last failed login etc).

Here is a groovy example for listing all the attributes for a given group:

```
import com.atlassian.jira.component.ComponentAccessor
def cs = ComponentAccessor.crowdService
def group = cs.getGroupWithAttributes(group.name)
group.getKeys()
```

<br />

In my example above, the key for the new Attribute is 'com.acme.jira.group-editor' .

You can call it whatever you want. I use com.mycompany as a prefix to ensure I don't accidentally overwrite a system or plugin attribute.


Tags: confluence-server

groovy

jira

object

property

script

server