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

groovy.lang.MissingPropertyException: No such property: issue for class: Script139

Deleted user September 27, 2017

 I'm attempting to create a Confluence page whenever a user makes a new task/story in JIRA. The two applications, JIRA and Confluence, are linked together.

 

In the process I'm trying to learn Script Runner. However, it appears not even Adaptavist's own examples are compiling? A direct copy/paste of their example provides the error of:

 

groovy.lang.MissingPropertyException: No such property: issue for class: Script139 at Script139.run(Script139.groovy:24)


Am I doing something wrong here? I'm running it in the JIRA script console, at..

/plugins/servlet/scriptrunner/console?section=script_console

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Thanos Batagiannis [Adaptavist]
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.
September 27, 2017

Hi Cristian,

This script is written to be used as a post function, where the issue provided in the binding. 

If you want to run it via the script console then replace line 25 with 

import com.atlassian.jira.component.ComponentAccessor


def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("ISSUEKEY-1")

regards, Thanos

Deleted user September 27, 2017

Where is ComponentAccessor imported from?

And what do you mean by post function; How are these tested(and deployed)?

As per running it in the console, your solution wouldn't work, as the rest of the code tries to access properties within issue(which will throw an error) :)


Thanos Batagiannis [Adaptavist]
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.
September 27, 2017

Hi Cristian,

I updated the script in order to include the ComponentAccesso import. 

PostFunctions is a key concept in Jira's workflows - Advanced workflow configuration

Script Runner offers few built in post functions. The script you found is for a custom script post function.

What he script actually does is that is trying to get some issue properties and create a confluence page with them. So the script in the example you found is getting the issue which is in the transition. In script console there is no issue in transition. 

Therefore you have to get a known issue, by key, using the issueManager. The rest of the script remains the same. Did you try to run it ? You have to make sure that you set up an application link between your JIRA and Confluence instances 

Hope what I say makes sense.

regards, Thanos

Deleted user September 28, 2017

It makes some sense - I'm not new to groovy, but i am to the atlassian stack :-) Your initial scripts works(at least for syntax, i have some problems with confluence link I think) - so there's something to play around with.

 

At least now, I get "You're not allowed to view that space, or it does not exist" with a 403 thrown back; but it is linked correctly on both sides and says CONNECTED. So it's a bit strange. 


Deleted user September 28, 2017

Some elaboration:

I have created a confluence space, the space key is "SD"

I have created a sample JIRA project, key is BEC.

 

I set the issuekey to BEC-10(it exists) and space to "SD" as in your sample code - also exists.


Now I get this response:

 

{"statusCode":500,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.ServiceException: java.lang.UnsupportedOperationException: Cannot convert from null to storage"}


Any idea what it could mean? 

Thanos Batagiannis [Adaptavist]
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.
September 28, 2017

Edit your code so to include in the params

represenation: "storage", something like: 

def params = [
type: "page",
title: pageTitle,
space: [
key: "TEST" // set the space key - or calculate it from the project or something
],
body: [
storage: [
value: writer.toString(),
representation: "storage"
]
]
]

regards, Thanos

Deleted user September 28, 2017

Where do you declare the writer variable and what is it? 

Deleted user September 28, 2017

I got it working by adding the pageBody instead of writer. So that's nice.

I'm a bit confused; this works in the console now which is good. What would the steps to "deploy" this on the JIRA solution be?

So that f.e. a user creates a story, and the confluence page is then created by the script with the information. I can't seem to dig this out of the documentation?

Thanks :) 

Thanos Batagiannis [Adaptavist]
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.
September 28, 2017

Hi Cristian,

So in your scenario the script should be a custom script post function on the Create step. And in that case your issue will be

Issue issue = issue

as it is in the original script. Which actually means 

"Use the issue in transition"

In order to see hoe to set up a post function, follow the links I sent on my second comment. 

Shout if you need further assistance. 

Kind regards, 

Thanos 

TAGS
AUG Leaders

Atlassian Community Events