Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get USER from Insight Attribute

David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 7, 2022

Attempting to get the User from an Insight Attribute Field, so that the script can assign an issue to a user.

So far I am getting the value of: [1010422(JIRAUSER17910)]

I need to assign the issue to the same user.

 

I know there are other ways to do this with an Insight Post Function as that is how we have it today, but we need to add other checks in the process, so the script is required.

I have a way to do this with a JIRA Group from Insight, but the user is proving more difficult.

2 answers

1 accepted

3 votes
Answer accepted
David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2022

Managed to figure this out :-) 

Here is the script that I have which gets the Insight Object from a custom field, obtains the Insight Attribute value which is of type 'USER'

Then with the returned value, subtract the user Key which is then used to obtain the JIRA User value.

Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade")
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass)
def objectAttribute = null
def attributeRef = 1615


def CompanyProductField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11603")
def CompanyProductValue = issue.getCustomFieldValue(CompanyProductField);
def Test = CompanyProductField.getValue(issue)
def CompanyProduct = Test[0]

LogEntry.info("Result:" + CompanyProduct)

if (CompanyProduct) {
objectAttribute = objectFacade.loadObjectAttributeBean(CompanyProduct.getId(), attributeRef)
}
if (objectAttribute){
def objectAttributeValue = objectAttribute.getObjectAttributeValueBeans()[0].toString()

LogEntry.info("objectAttributeValue:" + objectAttributeValue)
def UserKey = objectAttributeValue.substring(objectAttributeValue.indexOf('(')+1,objectAttributeValue.indexOf(')'))
LogEntry.info("UserKey:" + UserKey)

def Agent = userManager.getUserByKey(UserKey)
LogEntry.info("Agent:" + Agent)
}
2 votes
Mikael Sandberg
Community Champion
March 7, 2022

I assume that you are using the user field in Insight. If that assumption is correct then you can use the dot (.) notation in Insight to get the name of the user. Here is part of the automation I am using to get approvers for different applications

Screen Shot 2022-03-07 at 12.12.49 PM.png

David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2022

Hi @Mikael Sandberg 

Yes I understand that it works in the Automation plugin, but this doesn't work the same when using Scriptrunner, unless I am missing something.

Script console script failed: groovy.lang.MissingPropertyException: No such property: name for class: com.riadalabs.jira.plugins.insight.services.model.ObjectAttributeValueBean

We do have the automation plugin, but this has caused more issues with rules being throttled and our requirements need more than this plugin can provide from a logic and action perspective.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events