Hi,
I recently started using scriptrunner for JIRA although it seems I've fallen at the first hurdle.
In order to access the value of a field in a given JIRA issue it's my understanding that the "ComponentAccessor" class is required. Unfortunately I'm unable to import it and output a field value to the logs.
The script has one line:
import com.atlassian.jira.component.ComponentAccessor
Output:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 1: unable to resolve class com.atlassian.jira.component.ComponentAccessor @ line 1, column 1. import com.atlassian.jira.component.ComponentAccessor ^ 1 error at com.adaptavist.sr.cloud.workflow.AbstractScript.parseScript(AbstractScript.groovy:51) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:32) at com.adaptavist.sr.cloud.workflow.AbstractScript$evaluate$2.callCurrent(Unknown Source) at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:27) at ConsoleScriptExecution1_groovyProxy.run(Unknown Source)
I'm using JIRA cloud, if you require any further information please let me know.
I did a bit more digging and found an alternative way to access the value.
It's done like this:
import org.apache.log4j.Logger;
def inputClinicalRisk = 'customfield_16261'
def valueClinicalRisk = issue.fields[inputClinicalRisk]['value'] as String
def inputIGRisk = 'customfield_16262'
def valueIGRisk = issue.fields[inputIGRisk]['value'] as String
def inputCustomersImpacted = 'customfield_16263'
def valueCustomersImpacted = issue.fields[inputCustomersImpacted]['value'] as String
def inputImpact = 'customfield_16264'
def valueImpact = issue.fields[inputImpact]['value'] as String
def inputUrgency = 'customfield_16265'
def valueUrgency = issue.fields[inputUrgency]['value'] as String
def log = Logger.getLogger("com.onresolve.jira.groovy");
log.info ("Clinical Risk:"+valueClinicalRisk);
log.info ("IG Risk:"+valueIGRisk);
log.info ("Customers Impacted:"+valueCustomersImpacted);
log.info ("Impact on Business:"+valueImpact);
log.info ("Urgency:"+valueUrgency);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Even though I have added the dependency(jira-test) still ComponentAccessor is not getting resolved. I came to this link searching for the answer but the reply seemed random
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My issue was that I am using JIRA Cloud and the ComponentAccessor is not available on the cloud version of the product.
The way to access these things on cloud is to use the "issue" object. The issue array becomes available on script listener when the event selected under "On these events" is related to an issue, for example "Issue Updated".
You can then write something like:
def valueClinicalRisk = issue.fields['customfield_16261']['value'] as String
You can get the ID for a custom field by going to Settings -> Issues -> Custom Fields and click "configure" on the field. The URL will end with "customFieldId=xxxxx"
reference this as "customfield_xxxxx".
The issue object is only a small amount of functionality available in scriptrunner cloud. Using the JIRA API you can do all kinds of things.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Let me describe my issue in detail.I am creating a JIRA ticket using issue client.As part of the issue creation I am attaching files as well as supplying values to custom field. Because of this unresolved MockComponentWorker issue I am not able to proceed.Have you done something similar and written unit tests for same? Appreciate any help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.