Forums

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

unable to resolve class com.atlassian.jira.component.ComponentAccessor

Rob Cormack January 22, 2019

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.

 

1 answer

1 accepted

0 votes
Answer accepted
Rob Cormack January 22, 2019

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);

Debasish.Mahapatra2 March 5, 2019

what is this

Rob Cormack March 5, 2019

What are you struggling with?

Debasish.Mahapatra2 March 5, 2019

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

Like # people like this
Rob Cormack March 5, 2019

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.

Like sciencecovskij likes this
Debasish.Mahapatra2 March 5, 2019

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  

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events