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
2 votes
Answer accepted
DORIAN KERSCH
Contributor
April 12, 2019

After talking with @JamieA at Summit19 - he provided me with a solution.

 

Step 1:

Create the custom field with the issue picker: https://scriptrunner.adaptavist.com/5.5.0/jira/script-fields/issue-picker.html#_usage .

 

Step 2:

Create a behavior for all projects (or just the projects you care about) and potentially the issue types you care about.

Inside the initializer add:

getFieldByName("Picker").setConfigParam("currentJql", "project = ${issueContext.projectObject.key} and <insert the rest of your query>") 

 

Note: Unfortunately you have to hard code the query in both places. You technically don't need to hardcode it in step 1, but you should because of the second points below. 

Note: Unfortunately there isn't a "getConfigParam" to get the current JQL. I mentioned this to Jamie and he may fix it.

Note: Ideally issue picker would just support something like {issue.project.key} in the query. I mentioned this to Jamie and he may fix it.

Daniel
Contributor
August 20, 2019

Who is Jamie and is there a ticket to vote on that it really happens?

Like Erik Buchholz likes this
DORIAN KERSCH
Contributor
August 20, 2019

Jamie is/was one of the lead developers for Script Runner (he was the creator of it before it was bought out by Adaptavist). 

I don't know if there is a ticket for this, but the workaround above is still valid. Feel free to create a support ticket with Adaptavist and post it here (if they have a public tracker).

John Roberts-Davies
June 18, 2021

I would like to refer to the current issue, not the current project.

So I guess

project = ${issueContext.projectObject.key}

 should be replaced.

Could someone let me know what syntax to use?

John Roberts-Davies
June 19, 2021

I found a solution.

def MyKey = underlyingIssue?.key
getFieldByName("Picker").setConfigParam("currentJql", "<insert JQL here containing ${MyKey} to represent the current issue key>")
 
Like Eitan Yomtovian likes this
TAGS
AUG Leaders

Atlassian Community Events