Can't get isUserMemberOfRole() to work

Im in need of the functionallity of the isUserMemberOfRole. When I use it in my validator script an exception is thrown saying there is "No Signature of method" that is applicable for argumnent types String.

I have tried to find any documentation of it but only found it in various examples where it is used directly with a String as input. Is there any page with documentation of such Script runner closures?

2 answers

1 accepted

This widget could not be displayed.

Those functions are only available in the condition block and the additional actions block of built-in scripts. You can just copy the impl to your script:

Closure isUserMemberOfRole = {String role ->
            ProjectManager projectManager = componentManager.getProjectManager()

            ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class)
            ProjectRoleActors projectRoleActors =
                projectRoleManager.getProjectRoleActors(projectRoleManager.getProjectRole(role), issue.getProjectObject())
            projectRoleActors.getUsers().contains(currentUser)
        }

where currentUser might be:

ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

This widget could not be displayed.

That error means you're passing the wrong thing into the function. This may well not really be a script-runner problem, it's to do with the API in Jira.

How are you using isUserMemberOfRole? (I mean, the full use, is it from a manager object of some sort?)

I actually only use it in an if statement such as:

if (isUserMemberOfRole("Project Manager")){
   something
}else {
   somethingelse
}

From what Ive seen on other posts I presumed it is something script-runner provides during runtime. In my IDE, calling the function show there is no linkage to anything in my API. Is there an import or something I should use?

During the exception it says it tried to link it to something in the "org.codehaus.groovy.jsr223.GroovyScriptEngineImpl", probably because it couldnt find any match.

Thanks for your quick reply!

Yup, I see what you mean. Could you give us a bit more of the error message?

There's usually a bit after that error saying something like "can't do this, try flibble.impl.jira.string[Role: blada][fungus]" (Sorry, that's a string of rubbish, I can't remember a typical error message - the important bit is that it tries to tell us somethign about what the function is expecting, with a "try" in the middle of the block)

Unfortuenately i get two "... 180 more" lines message that dont show in catalina.out. Is there a way to expand the error message and get it all written to the log? I tried it in the script-runner consol also but it resulted in the same with to many traces.

Yeah, java stack traces - helpful for developers, gives the rest of us nightmares trying to unpick them

Could you look for a line that says "Possible solutions" - it should happen almost immediately after the "no signature of method" line - include both of those lines here!

Ive seen those possible solutions other times when i have made an error but this time there isn't any entry with possible solutions.

2014-07-03 12:45:28,919 http-8080-2 ERROR stefanj 765x19739x1 86higu 10.10.2.58,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.isUserMemberOfRole() is applicable for argument types: (java.lang.String) values: [Project Manager]
2014-07-03 12:45:28,920 http-8080-2 ERROR stefanj 765x19739x1 86higu 10.10.2.58,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyValidator] Script validator failed on SES-766: /srv/jira-home/scripts/validators/CheckIfCurrentUserIsInRole.groovy
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.isUserMemberOfRole() is applicable for argument types: (java.lang.String) values: [Project Manager]
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:195)
        at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:102)
	...

Maybe it cant connect or relate the method call to anything in the vicinity.

Ive been thinking about that it says "org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.isUserMemberOfRole()" - this must be something connected to the usual groovy, shouldn't it be something connected to script runner?

Where should it look for that method? Ive read that Jamie calls the method an "closure defined in the script runner plugin", do you know what that means or where I can read about such methods?

Hmm, there's no suggestions coming out there, not sure why I'm getting them.

It really doesn't seem to like the string you're passing in. I wonder if feeding it a "role" object would work.

You are using it in the right way IIRC. I think the issue is it's not available in the script binding for some reason. This is in the script for a "simple scripted validator", or is it your own script? A screenshot might help.

Ah, ok, I've not used that function, thanks for the correction before my suggestion sent Stefan off down the wrong route!

No worries, thanks for helping.

Its my own script. Its very basic because i just wanted to confirm that I used the isUserMemberOfRole method correctly.


import org.apache.log4j.Category

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)

	if(isUserMemberOfRole("Project Manager")){
				
		log.debug "User is in Role Project Manager"
	}else {		
		log.debug "User is not in Role Project Manager"	
	}

Or did you mean a screenshot of the stack trace?
Appreciate the help from you both!

This worked great, thanks for taking the time! Can I just accept your post as the answer in someway?

If I had any karma to give, you would get it!

I converted it to an answer, you can accept that. Thanks!

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

115 views 2 0
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