Scriptrunner + Insight - Get attribute value from custom field in Insight object

Anthony Degrande July 3, 2020

Hello all,

We're currently reviewing our Jira Service Desk setup and we would like to have all of our tickets to be approved by software or business application owners.

For this, we would create an object (for each application) in Insight and add custom fields to the objects (programmer and approver). 

After creation of a ticket, we would like to use a scriptrunner script as post function, where we get the approver and programmer from the insight object, based on the chosen software in the ticket.

I've found  some code on the internet, but it doesn't work in our environment... 

 

This is what i had found:

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

CustomField Benutzername = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11003) // ID von Customfield "Anfrage für"
def myValue = Benutzername.getValue(issue)
def myObjectBean = myValue[0]
def myAttrValue = objectFacade.loadObjectAttributeBean(myObjectBean.getId(), 1293).getObjectAttributeValueBeans()[0]; // ID von Attribute "Benutzername AD" vom Object Person
def myString = myAttrValue.getValue()

 

Unfortunately, the first line of code already produces an error

Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade")

if i change it to 

Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().loaddClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade")

then this error is gone, but the next error appears on:

def myObjectBean = myValue[0]

Here i get:

[Static type checking]- Cannot find matching method

java.lang.Object#getAt(int). Please check if the declared type is correct and if the method exists.

Possible solutins: getAt(java.lang.String), putAt(java.lang.String, java.lang.Object), wait(), grep(), tap(groovy.lang.Closure), getClass() @ line 45, column 21.

 

Any help would be much appriciated!

 

Our current version are:

- Scriptrunner 6.3.0

- Insight 6.4.11

- Jira Server 7.11.2

1 answer

0 votes
Sandra _Mindville_
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.
July 13, 2020

Hi Anthony.

There are ways to do this without using ScriptRunner, if I understand your need correctly. There are built in Insight post functions that can help.

I wrote a blog a few months ago explaining a use case similar to yours. Please check it out and see if that helps.

https://www.mindville.com/blog/automate-approval-workflows-in-jira

Kind regards,
Sandra

Vuyisanani November 27, 2020

Hi @Sandra _Mindville_ 

I had a look into your blog and also had few similar questions with @Anthony Degrande 

I have an App written in React (JS) and am using AWS Lambda's to post and request to Jira

I currently have an endpoint that filters the Object Schema and object that I want to get Objects data for Authorized user (populating their number, cell number and email on the front end)

Do you perhaps know how would I be able to update and Object attribute (Jira Insights) ? and also create a Jira Object from rest API ?

I currently found the script below for Updating Object attribute, but it doesn't really give much of help:

https://documentation.mindville.com/insight/5.0/insight-for-developers/groovy-script-examples/post-functions-script-examples/update-object-attribute

 

Thank you in advance.
Vuyisanani

Suggest an answer

Log in or Sign up to answer