Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

insight set object attribute value of type user by username

we have object type "user" with attribute "name" and attribute "user jira" (type user)

we would like to assign attribute "user jira" automatically based on mapping "user"."name" = username of "user jira"

manual assignement works but we would like to automate it.

can someone help me please. thank you.

1 answer

0 votes

Can you provide a bit more context around this operation?

Are your user objects populated automatically with some import?
Or are you looking to create user objects manually by providing the username in the attribute and have the "user jira" attribute automatically populated after saving so that object creators don't have to enter the same value twice?

yes, your second assumption is correct. populated on save and for existing objects. we have a a lot of user objects which must be connected to jira users (jira users are imported via ldap).

(further step could be create user objects also via ldap import)

thank you.

If you have your user object type connected to LDAP Import, you could just map the ldap attribute that contains your username to both the "name" and the "user jira" insight attribute and all the existing objects will be refreshed with the jira account.

You don't need to use automation for it. 

To have 1 field populated on the basis of another one on the create or update event requires a groovy script.

Here is something I cobbled together from other existing scripts I have:

import com.atlassian.jira.component.ComponentAccessor

def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectFacade)
def objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeFacade)
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeAttributeFacade)

def ATTRIBUTE_NAME_JIRA = 'Jira Account'

def objectType = objectTypeFacade.loadObjectType(object.objectTypeId)

doNameRefresh = true
if (this.binding.variables.containsKey('objectUpdateList')) {
doDateRefresh = this.binding.variable['objectUpdateList'].any {

if (doNameRefresh) {
def nameAttributeBean = objectTypeAttributeFacade.findObjectTypeAttributeBeans( { == ATTRIBUTE_NAME_NAME
if (!nameAttributeBean) {
log.error "Unable to find attribute with name: $ATTRIBUTE_NAME_NAME"
def jiraUserAttributeBean = objectTypeAttributeFacade.findObjectTypeAttributeBeans( { == ATTRIBUTE_NAME_JIRA
if (!jiraUserAttributeBean) {
log.error "Unable to find attribute with name: $ATTRIBUTE_NAME_JIRA"
def name = object.getObjectAttributeBeans().find {
ObjectAttributeBean it -> it.objectTypeAttributeId ==
def jiraAttrVals = object.getObjectAttributeBeans().find {
ObjectAttributeBean it -> it.objectTypeAttributeId ==
def jiraAttrVal = jiraAttrVals ? jiraAttrVals[0].value : null
def jiraUser = ComponentAccessor.userManager.getUserByName(name as String)
if (!jiraUser) {
log.error "Unable to find jira user with name $name"
if (jiraAttrVal != jiraUser.key) {
def newJiraAttr = object.createObjectAttributeBean(jiraUserAttributeBean)
def newJiraAttrVal = newJiraAttr.createObjectAttributeValueBean()
newJiraAttrVal.setValue(jiraUserAttributeBean, jiraUser.key)
objectFacade.storeObjectAttributeBean(newJiraAttr, EventDispatchOption.DO_NOT_DISPATCH)

You just need to adjust ATTRIBUTE_NAME_NAME and ATTRIBUTE_NAME_JIRA save the script in your jira-home directory, add the script to the insight whitelist and then create an Insight automation that fires on create and update and has this script as the action.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Software

👋 Looking for 15-20 volunteers to test Atlassian training content

Hi everyone! Are you interested in beta testing Atlassian University’s newest (unreleased!) training course? We’re looking for 15-20 volunteers to test our newest training course, Basic reporting...

867 views 25 28
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you