I'm curently using script runner to create subtasks for several types of issues and I'm tring to find a way to automaticly assign these subtasks to users that I define in custom fields.
Right now I am manually assigning these which is tedious work.
the following script does something similar to what I need but I don't know how to edit it to make it work for me:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.util.IssueChangeHolder ComponentManager componentManager = ComponentManager.getInstance(); CustomFieldManager customFieldManager = componentManager.getCustomFieldManager(); IssueManager issueManager = componentManager.getIssueManager(); CustomField srcField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "CustomField"} cfwt = issue.getCustomFieldValue(srcField); if (cfwt == "CustomFieldValue001"){ issue.setAssignee(ComponentManager.instance.userUtil.getUserObject('vend001')) } else if (cfwt == "CustomFieldValue002"){ issue.setAssignee(ComponentManager.instance.userUtil.getUserObject('vend002')) } else if (cfwt == "CustomFieldValue003"){ issue.setAssignee(ComponentManager.instance.userUtil.getUserObject('vend003')) }
Hey Guys,
I am new to Plugin/Coding, that being said where do I need paste this code to assign the subtask using an person defined in an custom field in the parent issue. Thanks in advance.
If you're using the "create subtask" built-in script from Script Runner, in the "additional issue actions" block.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Jamie. One last question using you plugin I believe that you can create multiple subtasks in one go under transition post function. Is there any place where I can refer to step-by-step instruction on how to setup creating more than 2 subtasks ? Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Simplest thing is just to add multiple post-functions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This code can be used to assign a subtask to a person defined in a custom field (in this example the field is named "Team Leader")
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.fields.CustomField ComponentManager componentManager = ComponentManager.getInstance(); CustomFieldManager customFieldManager = componentManager.getCustomFieldManager(); // List all available fields //customFieldManager.getCustomFieldObjects(issue).each {log.debug("Field: " + it.name)} try { CustomField srcField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Team Leader"} // log.debug("srcField: " + srcField) def cfValue = issue.getCustomFieldValue(srcField); // log.debug("cfValue: " + cfValue) issue.setAssignee(cfValue); } catch (Exception e) { log.error(e.message, e) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you mark at least one answer as accepted. It's also nice to vote up and "like comments" for the ones you found helpful.
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.
try with the following code
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.fields.CustomField ComponentManager componentManager = ComponentManager.getInstance(); CustomFieldManager customFieldManager = componentManager.getCustomFieldManager(); CustomField srcField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "CustomField"} def cfwt = issue.getCustomFieldValue(srcField); def cf = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Team Leader" } def cfValue = issue.getCustomFieldValue(cf) issue.setAssignee(cfValue);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This does not seem to work either. I cannot see if it's a syntax fault of nonworking code...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
error message:
2013-09-02 09:45:07,913 ajp-bio-127.0.0.1-8009-exec-166 ERROR jonas.nilsson 585x22319x1 1lstgh5 192.168.1.195 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at javax.script.ScriptEngine$eval.call(Unknown Source)
at com.onresolve.jira.groovy.canned.utils.ConditionUtils.doAdditional(ConditionUtils.groovy:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) <+2>
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:43)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:88)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at com.onresolve.jira.groovy.canned.workflow.postfunctions.AbstractCloneIssue.doScript(AbstractCloneIssue.groovy:76)
at com.onresolve.jira.groovy.canned.workflow.postfunctions.CreateSubTask.super$2$doScript(CreateSubTask.groovy) <+2>
at java.lang.reflect.Method.invoke(Unknown Source)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you change the string "CustomField" in the example code?
Add some logging so you can see what exactly is null...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if you want to set assignee from user coustom field then try with this code
CustomField userField= getCustomFieldObjectByName("User Field name"); //change field name here User userFieldValue=(User)issue.getCustomFieldValue(userField); issue.setAssignee(userFieldValue)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is the error I get when trying your code together with imports
Code used:
"
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
import com.atlassian.jira.component.ComponentAccessor
CustomField userField= getCustomFieldObjectByName("Team Leader");
User userFieldValue=(User)issue.getCustomFieldValue(userField);
issue.setAssignee(userFieldValue);
"
error output:
2013-08-27 13:53:09,945 ajp-bio-127.0.0.1-8009-exec-146 ERROR jonas.nilsson 833x17983x1 uyjn6y 192.168.1.195 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executi ng post-function javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getCustomFieldObjectByName( ) is applicable for argument types: (java.lang.String) values: [Team Leader] at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
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.