Hello,
I use JIRA 5.0 and I need to set assignee to particular user when issue is resolved in specific project. I cannot use existing post functions to set assignee because workflow is not unique and used for other projects. I think post function script should serve very well for this purpose. I found an example how to set user to specific one at
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.comments.CommentManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.util.ImportUtils import com.atlassian.jira.user.util.DefaultUserManager import com.atlassian.crowd.embedded.api.User MutableIssue issue = issue UserManager userManager = UserManager.getInstance(); User usera = userManager.getUser('my_user_name'); issue.setAssignee(usera);
but it does not work for JIRA5.0 and returns the following error
Script9.groovy: 20: unable to resolve class UserManager
@ line 20, column 13.
UserManager userManager = UserManager.getInstance()
^
1 error
I guess getInstance() method does not exist in JIRA5.0.
Could you please advise what method I can use to set user to particular one?
Thanky you in advance.
Regards, Georgiy
Try this
ComponentManager.getUserUtil.getUser('ngs')
I tried
User usera = ComponentManager.getUserUtil.getUser('ngs')
but it returned error
2012-07-03 14:46:57,813 http-80-5 ERROR admin 886x1216x1 13ft31r 10.161.201.37 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: getUserUtil for class: com.atlassian.jira.ComponentManager
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try
ComponentManager.getInstance().getUserUtil.getUser(
'ngs'
)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm syntax errors . i am sorry , use the below code
ComponentManager.getInstance().getUserUtil().getUser(
'ngs'
)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you sure you modified the script? The error seems to suggest the old code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the same error :(
2012-07-03 15:04:37,658 http-80-4 ERROR admin 904x1287x1 13ft31r 10.161.201.37 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: getUserUtil for class: com.atlassian.jira.ComponentManager
2012-07-03 15:04:37,658 http-80-4 ERROR admin 904x1287x1 13ft31r 10.161.201.37 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: getUserUtil for class: com.atlassian.jira.ComponentManager
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i also used simplier view as
componentManager = ComponentManager.getInstance()
userUtil= componentManager.getUserUtil()
usera = userUtil.getUser('ngs')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
WC .,... :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For the project try the below code , even apply some logging to check whether you get the project object
Project project=ComponentManager.getInstance().getProjectManager().getProjectObj(issue.getProjectObject().getId())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I used
project=ComponentManager.getInstance().getProjectManager().getProjectObj(issue.getProjectObject().getId())
"Project" returned error that class is unknown. I added print
System.out.println("Project is:" +project);
and it returns "Project is:Project: MYPROJECT"
so, now i need to parse the string to get the project name.
I guess "split" can be used.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are getting the project object , try
System.out.println("Project is:" +project.getName());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's what I was looking for! Thank you very much!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Georgiy, Can you please advise what is the final script that you are using. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please point how I can read project from the issue? as I need to set assignee to particular user only in specific project.
Thank you.
Regards, Georgiy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try importing below interface in your script
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you! It helped to resolve the error mentioned in the mail above, but now I get another error
2012-07-03 13:43:03,686 http-80-2 ERROR admin 823x910x1 13ft31r 10.161.201.37 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.user.util.UserManager.getInstance() is applicable for argument types: () values: []
2012-07-03 13:43:03,686 http-80-2 ERROR admin 823x910x1 13ft31r 10.161.201.37 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.user.util.UserManager.getInstance() is applicable for argument types: () values: []
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)
which I guess should not appear. Do you know what might be wrong, please?
Regards, Georgiy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try the below code
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.comments.CommentManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.util.ImportUtils import com.atlassian.jira.user.util.UserManager import com.atlassian.crowd.embedded.api.User MutableIssue issue = issue User usera = UserManager.getUser('my_user_name'); issue.setAssignee(usera);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I guess you are not using quotes
Try this
User usera = UserManager.getUser(
'ngs'
); OR
User usera = UserManager.getUserObject(
'ngs'
);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It didn't help. The error is still there :(
2012-07-03 14:05:58,099 http-80-2 ERROR admin 845x1060x1 13ft31r 10.161.201.37 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.user.util.UserManager.getUser() is applicable for argument types: (java.lang.String) values: [ngs]
Possible solutions: getAt(java.lang.String)
2012-07-03 14:05:58,099 http-80-2 ERROR admin 845x1060x1 13ft31r 10.161.201.37 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.user.util.UserManager.getUser() is applicable for argument types: (java.lang.String) values: [ngs]
Possible solutions: getAt(java.lang.String)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
actually I used quotes. My line was exactly the same as suggested
User usera = UserManager.getUser('ngs');
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
getUser is not static
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
neither
User usera = UserManager.getUser(
'ngs'
);
NOR
User usera = UserManager.getUserObject(
'ngs'
);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.