Forums

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

Coding: How to read IQL Filter Scope from an Insight custom field?

Daz February 7, 2022

Hello Community,

Using Adaptvist ScriptRunner console, trying to read the Filter Scope string that has been defined on a custom field 'Business Group' in Jira. How does one programmatically obtain this please in the Groovy lang?

The configuration screen for the custom field is given below. Its the yellow bit I want to extract.

Capture.PNG

I've got this far but dont know how to read the Filter Scope attribute

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.Issue

...

def jiraField = "Business Group"

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName(jiraField as String)[0]
def config = customField.getRelevantConfig(issueObject)
..

1 answer

0 votes
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 Leaders.
April 23, 2022

I have not found a way to access the Insight custom field configuration. I tried.

I think the only remaining option is to use a sql query to do that.

Something like this if you have a jira_local resource defined in your Scriptrunner Resource tab

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.db.DatabaseUtil

def jiraField = "Business Group"
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName(jiraField as String)[0]
def config = customField.getRelevantConfig(issueObject)
def query = '''
select issue_scope_iql
from AO_8542F1_IFJ_DCF_CONNECT
where CUSTOM_FIELD_CONFIG_ID = :configId
'''
def iql = DatabaseUtil.withSql('jira_local'){sql->
sql.firstRow(query, [configId: config.id])[0]
}

or, to use pure code (less recommended)

import com.atlassian.jira.component.ComponentAccessor
import groovy.sql.Sql
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface

import java.sql.Connection

def jiraField = "Business Group"
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName(jiraField as String)[0]
def config = customField.getRelevantConfig(issueObject)
def query = '''
select issue_scope_iql
from AO_8542F1_IFJ_DCF_CONNECT
where CUSTOM_FIELD_CONFIG_ID = :configId
'''


def
delegator = ComponentAccessor.getComponent(DelegatorInterface) as DelegatorInterface
def helperName = delegator.getGroupHelperName("default")
Connection conn = ConnectionFactory.getConnection(helperName)
Sql sql = new Sql(conn)

try {
def iql = sql.firstRow(query, [configId: config.id])[0]
} catch (err) {
log.error("error occurred - $err")
} finally {
sql.close()
}

Suggest an answer

Log in or Sign up to answer