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

 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

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

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


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

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. 


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? 

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

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

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

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 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

137 views 0 3
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you