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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,615
Community Members
 
Community Events
176
Community Groups

Getting No such property error trying to use groovy script in script root

Edited

Inline script:
   EPAutoLabel.process(issue);

Error Generated:
2017-05-03 09:05:05,852 ERROR [workflow.ScriptWorkflowFunction]:
*************************************************************************************
2017-05-03 09:05:05,864 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: NFRP-47, actionId: 181, file: <inline script>
groovy.lang.MissingPropertyException: No such property: EPAutoLabel for class: Script130
at Script130.run(Script130.groovy:1)

/var/atlassian/application-data/jira/scripts/EPAutoLabel.groovy:

 

 
//
// EPAutoLabel.groovy
//
// v1.0.0 2017-04-10 rconner Initial release
//

import com.atlassian.jira.bc.issue.label.LabelService
import com.atlassian.jira.bc.issue.label.LabelService.AddLabelValidationResult
import com.atlassian.jira.component.ComponentAccessor


public class EPAutoLabel
{

static List<String> process(com.atlassian.jira.issue.Issue issue)
{
def matchPerformance = ["web page", "response time", "CSS", "performance", "Javascript"];
def matchReliability = ["synchronous", "web tier", "load balancer"];
def matchSecurity = ["authentication", "password", "encryption", "security", "secure"];
def matchSupportability = ["customer service", "error message"];

List<String> listAddLabels = new ArrayList<String>();

def description = issue.getDescription();

matchPerformance.any {String match ->
if (description.contains(match))
{
listAddLabels.add("NFR-Performance");
return true;
}
}

matchReliability.any {String match ->
if (description.contains(match))
{
listAddLabels.add("NFR-Reliability");
return true;
}
}

matchSecurity.any {String match ->
if (description.contains(match))
{
listAddLabels.add("NFR-Security");
return true;
}
}

matchSupportability.any {String match ->
if (description.contains(match))
{
listAddLabels.add("NFR-Supportability");
return true;
}
}

if (! listAddLabels.isEmpty())
{
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def user = authenticationContext.getLoggedInUser()
def labelService = ComponentAccessor.getComponent(LabelService)

listAddLabels.each {String labelName ->
AddLabelValidationResult validationResult = labelService.validateAddLabel(user, issue.id, labelName)
if (!validationResult.errorCollection.hasAnyErrors())
{
labelService.addLabel(user, validationResult, false)
}
}
}

return listAddLabels;
}
}

 

2 answers

After some more searching, it appears I'm falling victim to a known bug that is still open:

https://productsupport.adaptavist.com/browse/SRJIRA-458

0 votes

Hi,

 

Can you please show me where you are putting the inline script.

And the versions you are using of Jira and Scriptrunner.

 

Thanks,

Johnson Howard

EPAutoLabel.groovy script is in the only "scripts" subdirectory...

/var/atlassian/application-data/jira/scripts/

 

And "inline" script consists of nothing more than:

"EPAutoLabel.process(issue);"

(without the quotes of course)
 In a Post Function Transition.

Jira -Version 7.3.6 Build Number 73017
ScriptRunner -Version 5.0.4

Ok so you will need to import the class. 

For example:

 

 

import exampleScripts.EPAutoLabel

def test = new EPAutoLabel()
test.process(issue)


Obviously you will have to change the import to match where your class is located. Make sure that the file name matches the class name.

Hmm. No such luck.

"Script31.groovy: unable to resolve class EPAutoLabel
line 1, column 1.
import EPAutoLabel"

EPAutoLabel.groovy is in the root (default package?) of scripts subdirectory.

I've also tried creating a subdirectory/package EP/AutoLabel.groovy and get the same error trying to import EP.AutoLabel -- unable to resolve class.

If I put the entire path to the class above the inline field, it has no problem finding/compiling the AutoLabel class, but inline seems to not see the scripts directory as documented.

I'm curious what version of ScriptRunner you are on, and whether this happens when your script runs or just in the code editor. There were some issues in the past where the static type checker fails to resolve classes from the script roots, but those should be fixed in the latest version.

Can you provide a screenshot of the error? Or are you seeing this in your log file on execution?

Jira -Version 7.3.6 Build Number 73017
ScriptRunner -Version 5.0.4

Originally, the entire method was inline -- I'm attempting to wrap it in a single method that can be easily called in any transition event inline script.

Script_Error.png

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events