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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Post Function to update Fix Version unable to import ComponentAccessor

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

0 votes

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/

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.

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

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

134 views 1 0
View question

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you