Forums

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

How to import groovy classes into Riada Insight groovy scripts?

Tomi Kallio
January 19, 2018

I have a simple groovy class that helps me deal with Insight object attributes. There is some amount of boilerplate code that is needed when dealing with objects, e.g. in automation when setting an attribute value based on other attributes.

The problem is the class must be inside the same groovy script in order for it to function. If I put it in an external file, the import will obviously fail since groovy does not know where to find the file.

Is it somehow possible to import classes directly from groovy files and use those classes in Insight automation groovy scripts (without compiling them to .class files)?

It would be best if we could import classes from within Script Runner's scripts directory.

Here's an example of using that class in automation:

import SimpleInsightObject


def obj = new SimpleInsightObject(object)

// Compose a new id based on two object attributes.
def id = obj.get("Attribute A") + " " + obj.get("Attribute B")

// Set the value of the "Id" attribute.
obj.setText("Id", id)

When I have a lot of automation tasks that deal with objects and their attributes, using such a helper class simplifies things greatly.

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Tobias Wolff
December 3, 2022

Mmh. I might have made some mistake, but it seems to work now. I was able to import my class on the "Console", instantiate it and run a method on it. Sorry for the noise.

TAGS
AUG Leaders

Atlassian Community Events