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.
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)
..
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()
}
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.