Introduction
To access the Lookup Manager public API in ScriptRunner , the user need to add these two annotations
-
@WithPlugin(pluginKey) which makes the service class available to the script
-
@PluginModule to inject instance of the module into script
Public APIs
(function(){ var data = { "addon_key":"com.appanvil.aura.aura", "uniqueKey":"com.appanvil.aura.aura__aura-inline-button1035816883133469517", "key":"aura-inline-button", "moduleType":"dynamicContentMacros", "moduleLocation":"content", "cp":"/wiki", "general":"", "w":"150px", "h":"64px", "url":"https://aura.cloudanvil.net/button.html?xdm_e=https%3A%2F%2Fakeles.jira.com&xdm_c=channel-com.appanvil.aura.aura__aura-inline-button1035816883133469517&cp=%2Fwiki&xdm_deprecated_addon_key_do_not_use=com.appanvil.aura.aura&lic=active&userAccess=true&cv=1000.0.0-dcac233cd72e&traceId=cf1f7b8bced016be8ac1d7440e95bd91&spanId=acb7cc35cd07b93e&traceSampled=0&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1ZGU3ZDhlM2JhNjBlMTBjZmQ2ODA3N2UiLCJxc2giOiJmNTJmMWE3NDBjMmVmODFjNDI0NDBkMGFmNDhkMzU4M2NhNjMyMTc4MjQyMGZiNTQxZjM3NzJmZjQ3YWNiZjU3IiwiaXNzIjoiQ29uZmx1ZW5jZToxNzk2NzM0ODQyIiwiY29udGV4dCI6e30sImV4cCI6MTc2MjUwOTY3NywiaWF0IjoxNzYyNTA5NDk3fQ.JtlwyCKuu_gJ3uoe-enKSJfQ-JgdG1Fa8lI8vmHPNh4", "structuredContext": "{\"license\":{\"active\":true},\"confluence\":{\"editor\":{\"version\":\"v2\"},\"macro\":{\"outputType\":\"email\",\"hash\":\"5eeac20a-f342-4fda-9a68-ad45fa14429f\",\"id\":\"5eeac20a-f342-4fda-9a68-ad45fa14429f\"},\"tracing\":{\"traceId\":\"cf1f7b8bced016be8ac1d7440e95bd91\",\"spanId\":\"acb7cc35cd07b93e\",\"sampled\":\"0\"},\"content\":{\"type\":\"page\",\"version\":\"8\",\"id\":\"2350678024\"},\"space\":{\"key\":\"LOOKUP\",\"id\":\"45973505\"}},\"url\":{\"displayUrl\":\"https://akeles.jira.com/wiki\"}}", "contentClassifier":"content", "productCtx":"{\"page.id\":\"2350678024\",\"macro.hash\":\"5eeac20a-f342-4fda-9a68-ad45fa14429f\",\"space.key\":\"LOOKUP\",\"tracing.sampled\":\"0\",\"page.type\":\"page\",\"content.version\":\"8\",\"page.title\":\"ScriptRunner Integration\",\"macro.localId\":\"bbebc795-424b-4b09-8fd3-d747749d3799\",\"macro.body\":\"\",\": = | RAW | = :\":\"params=JTdCJTIybGFiZWwlMjIlM0ElMjJDb250YWN0JTIwQWtlbGVzJTIwU3VwcG9ydCUyMGZvciUyMG1vcmUlMjBBUElzJTIyJTJDJTIyc2l6ZSUyMiUzQSUyMm1lZGl1bSUyMiUyQyUyMnNoYXBlJTIyJTNBJTIyY2lyY3VsYXIlMjIlMkMlMjJzdGF0ZXMlMjIlM0ElN0IlMjJpZGxlJTIyJTNBJTdCJTIyY29sb3JzJTIyJTNBJTdCJTIyYmFja2dyb3VuZCUyMiUzQSUyMiUyM2ZmZmZmZiUyMiUyQyUyMmxhYmVsJTIyJTNBJTIyJTIzMjY4NGZmJTIyJTJDJTIyb3V0bGluZSUyMiUzQSUyMiUyMzI2ODRmZiUyMiU3RCUyQyUyMnNoYWRvdyUyMiUzQSUyMmUyMDAlMjIlN0QlMkMlMjJob3ZlciUyMiUzQSU3QiUyMmNvbG9ycyUyMiUzQSU3QiUyMmJhY2tncm91bmQlMjIlM0ElMjIlMjMyNjg0ZmYlMjIlMkMlMjJsYWJlbCUyMiUzQSUyMiUyM2ZmZmZmZiUyMiU3RCUyQyUyMnNoYWRvdyUyMiUzQSUyMmUyMDAlMjIlN0QlN0QlMkMlMjJsaW5rJTIyJTNBJTdCJTIydHlwZSUyMiUzQSUyMm1haWwlMjIlMkMlMjJ2YWx1ZSUyMiUzQSUyMnN1cHBvcnQlNDBha2VsZXMuY29tJTIyJTdEJTdE\",\"space.id\":\"45973505\",\"params\":\"JTdCJTIybGFiZWwlMjIlM0ElMjJDb250YWN0JTIwQWtlbGVzJTIwU3VwcG9ydCUyMGZvciUyMG1vcmUlMjBBUElzJTIyJTJDJTIyc2l6ZSUyMiUzQSUyMm1lZGl1bSUyMiUyQyUyMnNoYXBlJTIyJTNBJTIyY2lyY3VsYXIlMjIlMkMlMjJzdGF0ZXMlMjIlM0ElN0IlMjJpZGxlJTIyJTNBJTdCJTIyY29sb3JzJTIyJTNBJTdCJTIyYmFja2dyb3VuZCUyMiUzQSUyMiUyM2ZmZmZmZiUyMiUyQyUyMmxhYmVsJTIyJTNBJTIyJTIzMjY4NGZmJTIyJTJDJTIyb3V0bGluZSUyMiUzQSUyMiUyMzI2ODRmZiUyMiU3RCUyQyUyMnNoYWRvdyUyMiUzQSUyMmUyMDAlMjIlN0QlMkMlMjJob3ZlciUyMiUzQSU3QiUyMmNvbG9ycyUyMiUzQSU3QiUyMmJhY2tncm91bmQlMjIlM0ElMjIlMjMyNjg0ZmYlMjIlMkMlMjJsYWJlbCUyMiUzQSUyMiUyM2ZmZmZmZiUyMiU3RCUyQyUyMnNoYWRvdyUyMiUzQSUyMmUyMDAlMjIlN0QlN0QlMkMlMjJsaW5rJTIyJTNBJTdCJTIydHlwZSUyMiUzQSUyMm1haWwlMjIlMkMlMjJ2YWx1ZSUyMiUzQSUyMnN1cHBvcnQlNDBha2VsZXMuY29tJTIyJTdEJTdE\",\"macro.truncated\":\"false\",\"content.type\":\"page\",\"output.type\":\"email\",\"page.version\":\"8\",\"macro.fragmentLocalId\":\"\",\"content.id\":\"2350678024\",\"tracing.traceId\":\"cf1f7b8bced016be8ac1d7440e95bd91\",\"macro.id\":\"5eeac20a-f342-4fda-9a68-ad45fa14429f\",\"tracing.spanId\":\"acb7cc35cd07b93e\",\"user.isExternalCollaborator\":\"false\",\"editor.version\":\"v2\"}", "timeZone":"UTC", "origin":"https://aura.cloudanvil.net", "hostOrigin":"https://akeles.jira.com", "sandbox":"allow-downloads allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-scripts allow-same-origin allow-top-navigation-by-user-activation allow-storage-access-by-user-activation", "pearApp":"true", "apiMigrations": { "gdpr": true } } ; if(window.AP && window.AP.subCreate) { window._AP.appendConnectAddon(data); } else { require(['ac/create'], function(create){ create.appendConnectAddon(data); }); } // For Confluence App Analytics. This code works in conjunction with CFE's ConnectSupport.js. // Here, we add a listener to the initial HTML page that stores events if the ConnectSupport component // has not mounted yet. In CFE, we process the missed event data and disable this initial listener. const __MAX_EVENT_ARRAY_SIZE__ = 20; const connectAppAnalytics = "ecosystem.confluence.connect.analytics"; window.connectHost && window.connectHost.onIframeEstablished((eventData) => { if (!window.__CONFLUENCE_CONNECT_SUPPORT_LOADED__) { let events = JSON.parse(window.localStorage.getItem(connectAppAnalytics)) || []; if (events.length >= __MAX_EVENT_ARRAY_SIZE__) { events.shift(); } events.push(eventData); window.localStorage.setItem(connectAppAnalytics, JSON.stringify(events)); } }); }());
Sample code
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.akelesconsulting.jira.plugins.rest.LookupService
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.json.JsonSlurper
@WithPlugin("com.akelesconsulting.jira.plugins.LookupManager")
@PluginModule
LookupService lookupService
def log = Logger.getLogger("LookupManager")
log.setLevel(Level.DEBUG)
log.debug("***** Get table list *****")
def tableListText = lookupService.getTableList()
def tableListArray = new JsonSlurper().parseText( tableListText )
tableListArray.each { log.debug it }
log.debug("***** Get table id by name *****")
int tableId = lookupService.getTableIdByName("Project Category Table")
log.debug("Table id: " + tableId)
log.debug("***** Get table information ****")
def table = tableListArray.find {table -> table.name.equals("Project Category Table")}
log.debug("Table information: " + table)
log.debug("***** Get column information*****")
def columns = table.columns
log.debug("Column information: " + columns)
log.debug("***** Execute lookup to get matching values *****")
def matchingValuesArray = lookupService.lookup(tableId, "Category", "BUSINESS", "Project Key")
matchingValuesArray.each { log.debug it }
log.debug("***** Get table entries by table id *****")
def tableEntriesText = lookupService.getTableEntriesById(tableId)
def tableEntriesArray = new JsonSlurper().parseText( tableEntriesText )
tableEntriesArray.each { log.debug it }
More Examples
- How to support Component field in Lookup Manager
- How to identify the workflows that are using Lookup Manager
- How to use Issue Properties in ScriptRunner Groovy scripts
- How to set a custom field value when date is between two other dates
- How to append values to multi-select fields
- How to import a table into Lookup Manager via ScriptRunner
- How to add a new row to Lookup Manager via ScriptRunner