Keep getting Property 'it' not found errors

Sebastian Dietrich October 23, 2015

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

1 vote
Answer accepted
Jamie Echlin _ScriptRunner - The Adaptavist Group_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 25, 2015
Sebastian Dietrich October 26, 2015

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

JamieA
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.
October 26, 2015

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

Edwin Stol October 13, 2016

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.
 

Jamie Echlin _ScriptRunner - The Adaptavist Group_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 17, 2016

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.

Edwin Stol October 23, 2016

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

JamieA
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.
October 23, 2016

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?

Edwin Stol October 24, 2016

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 votes
stuart_urquhart_l3t_com November 21, 2016

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

JamieA
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.
November 21, 2016

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.

0 votes
Jamie Echlin _ScriptRunner - The Adaptavist Group_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 25, 2015

can you post the errors as well?

0 votes
Nic Brough -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.
October 24, 2015

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 votes
Sebastian Dietrich October 24, 2015

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 votes
Nic Brough -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.
October 23, 2015

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events