InsightManager – Insight scripting made easy

Does your team use Insight, but find it to need a lot of manual care? Perhaps you looked at alleviating the situation but the stock post-function couldn’t get you all the way there?

Maybe you decided, today is the last time me and my team-mates do these manual steps so you started looking into the Insight Java Docs and examples but got intimidated and lost among the facades?

With the news that Atlassian will be bundling Insight with JSM we at Riada are happy to share something we have been working on for quite some time! InsightManager, it’s an open-source wrapper library intended to be used by both novice and experienced Groovy-scripters. Finally common Insight tasks can be scripted with just a few lines of code, all the methods are well documented and come with examples.

In this blog we will give you a brief overview of InsightManagers functionality, where and when it can be really useful and hopefully inspire the novice to write his/her first script and help the experienced developer deliver more and faster to the team. 

Illustration av en karamell inslagen i ett papper där det står "Insight - manager, customization made simple"

So what is it, and what does it do?

InsightManager is a Groovy-wrapper around the native Insight JAVA API, it takes away the need for obtuse beans, boilerplate code for setting up facades and instead allows flexible inputs and comes with accessible documentation and an expanding assortment of examples.

InsightManager can be used in any OnPrem ScriptRunner Groovy-script, is easy to install, well documented and open source. Great consideration has been given to making InsightManager as flexible as possible for the developer, for example taking away the need of the developer to figure out if a method needs ObjectId, ObjectKey or ObjectBean as input.

It will let you use native Insight functionality such as create/update/delete objects, trigger an Insight import, add/remove attachments all with a single row of code. But it also expands on the base functionality with methods such as renderObjectToHtml() and importObjectAttachments().

Enough already, show me!

Not convinced? Need a demonstration?

Fair enough, lets compare with Insights 58 row example code for creating an Insight object. Below is the equivalent example using InsightManager, 22 rows.

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
import customRiadaLibraries.insightmanager.InsightManagerForScriptrunner

//Needed by ScriptRunner to access Insight API´s
@WithPlugin(”com.riadalabs.jira.plugins.insight”)

//Instantiate InsightManager
InsightManagerForScriptrunner im = new InsightManagerForScriptrunner()

//Create a map with the attribute values
Map attributeValues = [

       ”Name”: issue.summary,
       ”Priority”: issue.priority.name,
       ”Description”: issue.description]

ObjectBean newObject

try {

   newObject = im.createObject(1,attributeValues)

}catch (Exception vie) {

   log.warn(”Could not create issue due to validation exception:” + vie.getMessage())

}

return true

We would argue this is not only less code to maintain, but also easier to overview and understand. Gone is the need to instantiate BeanFactories to craft beans with finicky inputs, it’s been replaced by a common Map. We also don’t need to use the numerical IDs for attributes, and can (if we wish) use the names of the attributes instead.

Here is a further example using a wider array of methods, in this case we are creating a new Employee object and adding it as head of an existing department:

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
import customRiadaLibraries.insightmanager.InsightManagerForScriptrunner

//Setup InsightManager
@WithPlugin(”com.riadalabs.jira.plugins.insight”)
InsightManagerForScriptrunner im = new InsightManagerForScriptrunner()

//Import all new Departments from AD (Import ID 9)
im.runImport(9, [”Departments”])

//Find the department object we are interested in schema 1
ObjectBean departmentObject = im.iql(1, ”ObjectType = Department AND Name = IT”).first()

//Created a new Employee (ObjectTypeId 5) with a map containing attributes
ObjectBean newEmployee = im.createObject(5,
        [
              Name: ”Nisse Hult”,
              JiraUser : ”JIRAUSER10000”,
              Department: departmentObject
        ]
)

//Update the department object with the new employee as department head and set a status
im.updateObjectAttributes(departmentObject,
          [
                     ”Department Head” : newEmployee,
                      Status : ”Up and running”
          ]
)

Check out the InsightManager github Wiki for documentation on all the methods!

InsightManager, not just CRUD!

InsightManager doesn’t only make native Insight functionality such as Creating/Reading/Updating/Deleting objects and running imports much easier. It also adds additional functionality such as renderObjectToHtml($object, $attributesToDisplay). 

Printscreen of InsightManager and ScriptRunner behaviours, during user input

Using InsightManager and ScriptRunner Behaviours, during user input.

With behaviours we can display additional dynamic data about selected objects while the JSM customer is inputting data. The JSM customer no longer needs to find and click the Insight magnifying-glass-icon to view attributes of available objects, instead they simply select an object in the field and get presented with it´s attributes.

Printscreen av Help Center

Using InsightManager and ScriptRunner Fragments, once the request has been created.

Once the customer has created the request, normally the customer would only see the labels of previously selected Insight objects. With InsightManager and ScriptRunner you can easily display attributes of any Insight object, not only the ones selected by the customer.

Would you like to get started?

Luckily that is super easy, all you need to do is add the library using ScriptRunner Editor. Headover to our Github repository for details on the installation, documentation of the methods and examples.

If you run into problems or have questions feel free to raise an Issue on github, if you’d like to suggest an improvement we’d be happy to evaluate your pull request!

If you’d like assistance and guidance on how to best use Insight and JIRA do please contact our professional services department.

Anders Lantz,
Atlassian Expert, head of Riadas Community Of Practice for Customizations and general tinkerer.