Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Interacting with Insight objects from Scriptrunner Server/Data-center

With the availability of Insight with all JSM Service Desk subscriptions, I'm seeing an uptick in community questions about ScriptRunner and Insight Custom fields and Insight objects.

As a long-time ScriptRrunner user, when we purchased Insight last year for our new JSM implementation, I started exploring their API and figuring out how to leverage scriptrunner for many different automation needs we had.

The Insight API and data model is quite complex and attempting to build a simple rule or condition based on the value of an attribute in a selected object in an Insight custom field can require many many lines of code.

Over the months, I've developed a fairly wide range of functions that make interractions with insight a breeze.

Here is an example...

Say you want to show/hide some fields using Behaviour base on an attribute of object selected in a custom field...

Behaviour will give you a string representation of the ObjectKey for the selected object.

So, you will need to

  1. use the ObjectFacade to get an actual ObjectBean,
  2. determine the ObjectType
  3. find the Attribute by name for the ObjectType
  4. get the value for that attribute from the object

It would look something like this:

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
@PluginModule ObjectFacade objectFacade
@PluginModule ObjectTypeFacade objectTypeFacade
@PluginModule ObjectTypeAttributeFacade objectTypeAttributeFacade

def attributeName = 'My Attribute Name'
def insightFormField = getFieldById(fieldChanged)
String objectKey = insightFormField.value //this assumes this insight custom field doesn't allow multiple

def object = objectFacade.loadObjectBean(objectKey)
def objectType = objectTypeFacade.loadObjectType(object.objectTypeId)
def attributeBean = objectTypeAttributeFacade.findObjectTypeAttributeBeans({ == attributeName}
def attributeValue = object.objectAttributeBeans.find{it.objectTypeAttributeId ==}?.objectAttributeValueBeans*.value

And you haven't even started to write the behaviour logic yet ... all that just to get a simple attribute value. And only if that attribute is a simple type like text.

What if the attribute I'm interested in is not directly in the selected object but in one of its outbound reference? 

For example, imagine a User object where the Manager attribute points to another object and I'm interested in looking up the title of the manager for the selected User.

What if I told you that this is all I have to write in my behaviour scripts to get the manager's title?

import com.qad.common.jira.utils.InsightUtils
def userFormField = getFieldById(fieldChanged)
def managerTitle = InsightUtils.getAttributeValueFromDotNotation(userFormField.value, 'Manager.Title')

Much simpler yeah?

What about having some lookup in a script (either behaviour or postfunction) in the Customer portal? You might have come across an issue where the portal user doesn't have access to view the insight objects. You might want to be able to perform some script-level lookup as a different user.

Well, that is all possible using this utility class that I've developed and I am now sharing with the community:

Obviously, since this is provided for free, there is no guarantee this will work for you in all your use cases or that I will help with support.
But if you get into troubles, tag me in a community post and I might be able to help.

Have fun scripting!





Hi Peter-Dave, this is awesome! I don't think your InsightUtils is made public yet, not able to see the content of your BitBucket link. :D 

Thanks for the heads-up @Benz Kek _Adaptavist_  please check it now. 

Like Benz Kek _Adaptavist_ likes this

Perfect! It's viewable now, many thanks! 

Dirk Ronsmans Community Leader Mar 29, 2021

Awesome work! I always hate the 10 hoops you need to jump through to make something "easy".

You're really taking the sting out of this one :)


Log in or Sign up to comment
Community showcase
Published in Marketplace Apps & Integrations

Bitbucket Smart Commits vs. Genius Commits - What's the difference?

If you already heard about Smart Commits in Bitbucket, know that you just stumbled upon something even better (and smarter!): Genius Commits by Better DevOps Automation for Jira Data Center (+ Server...

106 views 0 2
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