Keep getting Property 'it' not found errors

Whenever I iterate over e.g. subtasks via subTasks.each { ... and then access some attribute of that subTask with e.g. it.key I keep getting "Property 'it' not found errors".

The code is definitively correct (e.g. copy&paste from examples), so something in the configuration must be wrong...

6 answers

1 accepted

Yes you are right - as soon as I changed all outputs of "... ${it.key}..." to "... " + it.key + " ... " it worked like a charm...

I need to base64 encode inline scripts, then this goes away.

Hi @Jamie Echlin [Adaptavist],

Perhaps good to mention/change this in the documentation?
And is the base64 encoding in scope for the foreseeable future?
Cheers,

Edwin.
 

The base64 encoding happened some releases ago. If you are having this problem now, with the latest version, please let us know. If that's the case possibly some fields were missed.

Hi Jamie,

I encountered the problem on version 4.3.9.
Will try the implementation again on version 4.3.12 

(edit)

I'm getting 2 static type checking errors on the mentioned example, so this might be the problem as well. Did not encounter these on version 4.3.9 afaik.

Screen Shot 2016-10-23 at 18.38.59.pngScreen Shot 2016-10-23 at 18.39.04.png

The problem is that the type of "issue" cannot be inferred. How are you getting the issue? Can you give a screenshot that shows the context of how this is being run?

Hi Jamie,

This was a problem on my side. I tried to run it from Built-In Scripts instead of as a post-function.
When i insert it in the post-function it does not show any errors.
But when i execute the transition i still get the same error (Property 'It' not found).
The only thing i changed is the statusObject.name ="To Do" instead of 'Open' .

Do i need to make a reference to a certain transition ID? What's the 5 in your example? 

 

Update_Workflow_Transition_Script_Post-Function_Function_-_DEMO.pngTransition__Done_-_DEMO.pngWorkflow_Error_-_DEMO.png

0 vote

I suspect your iterator is incorrect, or trying to loop over data you haven't really got.  I'd suggest posting your code here so we can see what it's trying to do.

The code is from https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/auto-close-all-subtasks.html and only slightly changed.

But as mentioned above - the problem is very unlikely in the code. I get the same results with other code snippets as well... 

 

import com.atlassian.jira.component.ComponentAccessor
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def subTasks = issue.getSubTaskObjects()
subTasks.each {
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
setResolutionId(issue.getResolutionId())
setComment("*Transitioning* as a result of the *Transition* action being applied to the parent.")
}
// validate and transition subtask
def validationResult = issueService.validateTransition(user, it.id, 5, issueInputParameters)
if (validationResult.isValid()) {
def issueResult = issueService.transition(user, validationResult)
if (! issueResult.isValid()) {
log.warn("Failed to transition subtask ${it.key}, errors: ${issueResult.errorCollection}")
}
} else {
log.warn("Could not transition subtask ${it.key}, errors: ${validationResult.errorCollection}")
}
}
0 vote

Mmm, I'm not sure about some bits of your code, but it looks to me like your use of "it" is correct and it should not be throwing errors. I think I'd poke this at Adaptavist's Script Runner team (I'll poke them too - I'm curious to know where I'm reading it wrong, I've recently asked for more exposure to scripting, and they're actively looking for questions like this too)

0 vote

can you post the errors as well?

We're using ScriptRunner version 3.0.16 with JIRA 6.3 (we're due to upgrade soon) and trying to get Jamie's AddIssueToCurrentSprint.groovy script to run - see here: https://gist.github.com/jechlin/9789183

 

However, we get the error "property activeSprint not found".

 

Assuming the problem revolves around changing "... ${it.key}..." to "... " + it.key + " ... ", please can someone suggest a re-worked version of the code below:

 

if (activeSprint) {     log.info "Adding issue $issue to ${activeSprint.name}"     sprintIssueService.moveIssuesToSprint(loggedInUser, activeSprint, [issue] as Collection) } else {     log.info ("No active sprints were found for board: ${view.name}") }

 

Many thanks

Stuart

Either attach it as a file, rather than inline, or remove the log.info and log.warn lines.

Or upgrade to the latest version, but you would also need to upgrade your JIRA. In later versions there is a built-in workflow function that does this.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

85 views 0 5
Read article

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