Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Post Function to update Fix Version unable to import ComponentAccessor

Mitch Kent June 26, 2018

Hi,

I have just installed the cloud plugin for script runner and trying my first script. 

 

I have the following code and error:

import com.atlassian.jira.component.ComponentAccessor

def versionManager = ComponentAccessor.getVersionManager()
def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectObjByKey(issue.projectObject.key)

def versions = versionManager.getVersions(project)

def versionNoCodeChange = versions.find( it.name.equals('no-code-change') )

issue.setFixVersions(Arrays.asList(versionNoCodeChange))
2018-06-26 09:13:29.540 ERROR - 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

2018-06-26 09:13:29.579 ERROR - Class: com.adaptavist.sr.cloud.workflow.UpdateIssue, Config: [className:com.adaptavist.sr.cloud.workflow.UpdateIssue, uuid:cfe72c36-d292-4a17-99a5-ef39821aceb2, description:Set fix-version to no-code-change, enabled:true, executionUser:INITIATING_USER, additionalCode:import com.atlassian.jira.component.ComponentAccessor

def versionManager = ComponentAccessor.getVersionManager()
def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectObjByKey(issue.projectObject.key)

def versions = versionManager.getVersions(project)

def versionNoCodeChange = versions.find( it.name.equals('no-code-change') )

issue.setFixVersions(Arrays.asList(versionNoCodeChange)), userKey:mitch.kent]

 

This is, as I say, from the post-function screen.

 

I've searched and there are many posts around this functionality, but all seem to use the ComponentAccessor which I can't get, so am stuck on first hurdle.

 

Many thanks,

Mitch.

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 29, 2018

Hi Mitch,

I can confirm that your code is from the ScriptRunner for Jira Server plugin and the Jira Cloud version.

The reason for that is that the cloud version can only make changes to Jira via the Atlassian Rest API's as cloud does not have a Java API like the server version does.

This is described in more detail in the documentation page located here.

In order to set the version field for an issue inside of a post function on a cloud instance then you will need to use the Run Script post function which is described in the documentation here.

I have created some example code which shows how you can get the set the fix versions on an issue during a post function which can be viewed here. This code will show you how to set versions and can be used to create the script that you require.

If this answer has solved your issue can you please accept it in order to mark this answer as correct for users who are searching for a similar issue.

Regards,

Kristian

Mitch Kent June 29, 2018

Hi Kristian,

Thanks for your response.

The reason for that is that the cloud version can only make changes to Jira via the Atlassian Rest API's as cloud does not have a Java API like the server version does.


I realise this is the case, but I wrongly presumed the script runner plugin wrapped these things up in its own library - having looked into it more since I realise how wrong this is :)

This does mean that everything will become vastly more complex after this single example, for any future stuff I would like to work on. As such, there is no point in me continuing with the plugin, and have disabled it.

I appreciate your answer, but I wont be able to use or test it, so I can't mark it as correct.

Regards,

Mitch.

0 votes
Alexey Matveev
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.
June 26, 2018

Hello,

You are writing a script for Scriptrunner for Jira Server Version. You can not use same scripts for Cloud and Server version. Cloud is built upon Rest calls. Kindly have a look at the documentation for ScriptRunner Cloud:

http://scriptrunner-docs.connect.adaptavist.com/jiracloud/

Mitch Kent June 26, 2018

Thanks Alexey.

 

This looks massively more complicated and effort, though I can appreciate the reasons now I've read through the page.

 

I think I'll just delete the plugin.

TAGS
AUG Leaders

Atlassian Community Events