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.
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)
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.