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,456,779
Community Members
 
Community Events
176
Community Groups

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

1 accepted

0 votes
Answer accepted

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 user.name 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
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
import com.riadalabs.jira.plugins.insight.services.model.ObjectAttributeBean
import com.riadalabs.jira.plugins.insight.services.events.EventDispatchOption

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

def
ATTRIBUTE_NAME_NAME = 'Username'
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 {
it.attributeName in [ATTRIBUTE_NAME_NAME, ATTRIBUTE_NAME_JIRA]
}
}

if (doNameRefresh) {
def nameAttributeBean = objectTypeAttributeFacade.findObjectTypeAttributeBeans(objectType.id).find {
it.name == ATTRIBUTE_NAME_NAME
}
if (!nameAttributeBean) {
log.error "Unable to find attribute with name: $ATTRIBUTE_NAME_NAME"
return
}
def jiraUserAttributeBean = objectTypeAttributeFacade.findObjectTypeAttributeBeans(objectType.id).find {
it.name == ATTRIBUTE_NAME_JIRA
}
if (!jiraUserAttributeBean) {
log.error "Unable to find attribute with name: $ATTRIBUTE_NAME_JIRA"
return
}
def name = object.getObjectAttributeBeans().find {
ObjectAttributeBean it -> it.objectTypeAttributeId == nameAttributeBean.id
}.getObjectAttributeValueBeans()[0].value
def jiraAttrVals = object.getObjectAttributeBeans().find {
ObjectAttributeBean it -> it.objectTypeAttributeId == jiraUserAttributeBean.id
}?.getObjectAttributeValueBeans()
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"
return
}
if (jiraAttrVal != jiraUser.key) {
def newJiraAttr = object.createObjectAttributeBean(jiraUserAttributeBean)
def newJiraAttrVal = newJiraAttr.createObjectAttributeValueBean()
newJiraAttrVal.setValue(jiraUserAttributeBean, jiraUser.key)
newJiraAttr.setObjectAttributeValueBeans([newJiraAttrVal])
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.

Many thanks. It works.

Just two small errors in line 20. Correct is:

doNameRefresh = this.binding.variables['objectUpdateList'].any {

@Peter-Dave Sheehan Are you saying I can create a Schema in Insight with 'Email' and 'Username' and then bring that is from Okta to JSM somehow?  I am trying to find a way to bind assets being imported where one of the keys is primary user email and then linking that to the customer in JSM so I can display the assets on the portal and incidents.
Basically I am just trying to have something in Insight that can link from imported assets, to the JSM email address for customers to bind it all together.

The email is in JSM - the email is in our asset system that gets imported into Insight, I just can't see how to join them together.

Thanks

I've never used Okta, but a quick google search shows that they have an LDAP agent that can convert LDAP calls to their API.

So yes, if you create a User schema, you can import all your identity information from OKta. 

As part of that schema, if you have an attribute of type "User" you can map any Okta attribute that maps to your jira users's "username". This will create a link between those user objects and the internal jira users. 
You can only map jira user via the username. 

Then in your asset schema, it should be possible to link to another object type (the one containing the users).

I found we have the email available in our asset import that matches the email in Jira, I think its just my lack of understanding of insight on how to bind an imported email address to matching internal jira customer emails.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS

Atlassian Community Events