The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Run IQL (Insight) from groovy

Anna Protopapa
Contributor
July 14, 2021

How can we run an IQL statement from groovy? can we use and custom field values in the statement?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
PD Sheehan
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 Champions.
July 16, 2021

Where did you want to run this groovy? 
Is this in an insight post-function? or something similar? 

I'm more of a scriptrunner/groovy person. But I'm sure many things are similar.

One thing that's not clear from the Post Function groovy screen is what variables are available in the script by default.

But, we can use the Test Script functionality and examine the built-in variables by running a short script like:

log.info "${this.binding.variables}"

This will output something like:

[issue:JSP-1922, object:null, originalIssue:JSP-1922, log:com.riadalabs.jira.plugins.insight.services.groovy.GroovyLogger@449654d7, currentUser:p6s(p6s)

 Ok, so we know we can use "issue" and get a custom field object... here is a sample script i created to test this:

import com.atlassian.jira.component.ComponentAccessor
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade

def cfm = ComponentAccessor.customFieldManager
def cf = cfm.getCustomFieldObjectsByName('Name of Your Custom Field')[0]
def cfValue = issue.getCustomFieldValue(cf)

IQLFacade iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(IQLFacade)
iqlFacade.findObjects(/"Attribute"=$cfValue/)

If you need help writing groovy script, searching for "scriptunner" and what you're trying to do I the community will yield TONS of results.

DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events