Greetings...I'm wondering if the experts can get me past a related problem I'm having. Within a post function, I'm using the Script Runner to create subtask. I want to assign the subtask to a value based on a custom field of the parent. I've used the code @Cinnober Servicedeskposted here --
https://answers.atlassian.com/questions/205205/script-runner-assign-a-created-subtask
and it has gotten me farther than I've gotten before; however it is setting the Assignee to be the same as the parent Assignee and not the custom field value.
Here is the error I'm seeing in the logs:
/secure/CommentAssignIssue.jspa [groovy.canned.utils.ConditionUtils] No signature of method: com.atlassian.jira.issue.IssueImpl.setAssigneeId() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser) values: [OPR0474(opr0474)]
Possible solutions: setAssigneeId(java.lang.String), getAssigneeId(), setAssignee(com.atlassian.crowd.embedded.api.User), getAssignee()
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setAssigneeId() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser) values: [OPR0474(opr0474)]
Possible solutions: setAssigneeId(java.lang.String), getAssigneeId(), setAssignee
My current code:
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.crowd.embedded.api.User
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 == "Business Owner"}
// log.debug("srcField: " + srcField)
def cfValue = issue.getCustomFieldValue(srcField);
// log.debug("cfValue: " + cfValue)
issue.setAssigneeId(cfValue);
} catch (Exception e) {
log.error(e.message, e)
}
The value returned opr0474 is the Business Owner value.
Thoughts? Suggestions? Much appreciated as I've spent a fair amount of time trying to figure this out based on a lot of related posts.
Community moderators have prevented the ability to post new answers.
Hi John,
sorry, I edited this comment, probably it could solve your issue...
could you try to use the following code
issue.setAssignee(cfValue);
use setAssignee instead of setAssigneeId
Let me know,
Fabio
Thanks Fabio for input and help. I've seen other examples using the Mutableissue, but not sure how to set that up for my particular situation. And being new, I'm not even sure what you mean by the IssueManager. I'll look into it some more...really appreciate the help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
John,
could you perform a test using the proposed solution? It should work.
Regards,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Still gettting a similar error:
/secure/CommentAssignIssue.jspa [groovy.canned.utils.ConditionUtils] Assign To is "jbenjamin(jbenjamin)"
2014-04-30 20:39:59,482 http-bio-9080-exec-9 ERROR jbenjamin 1239x33454x1 15sxzoz 10.140.4.31 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setAssignee() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser) values: [jbenjamin(jbenjamin)]
Possible solutions: setAssignee(com.atlassian.crowd.embedded.api.User), getAssignee(), setAssigneeId(java.lang.String), getAssigneeId()
Updated code (as entered in the Additional Actions Code field of the script runner)
cfParent = customFieldManager.getCustomFieldObjectByName('Business Owner')
parentMyFieldValue = transientVars["issue"].getCustomFieldValue(cfParent)
log.error("Assign To is \"" + parentMyFieldValue + "\"")
issue.setAssignee(parentMyFieldValue)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does the fact that the parentyMyFieldValue comes back as jbenjamin(jbenjamin) reflect both the User ID and the User Key? I've seen some discussion about that recent change and wonder if that a factor here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi John,
jbenjamin(jbenjamin) is an Object DelegatingApplicationUser but setAssignee should receive com.atlassian.crowd.embedded.api.User object.
Try to do that :
... import com.atlassian.jira.user.ApplicationUsers ... def cfValue = issue.getCustomFieldValue(srcField); // log.debug("cfValue: " + cfValue) issue.setAssignee(ApplicationUsers.toDirectoryUser(cfValue)); ...
In this way you should convert the DelegatinApplicationUser to a User object.
Let me know,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.user.ApplicationUsers cfParent = customFieldManager.getCustomFieldObjectByName('Business Owner') parentMyFieldValue = transientVars["issue"].getCustomFieldValue(cfParent) log.error("Assign To is \"" + parentMyFieldValue + "\"") issue.setAssignee(ApplicationUsers.toDirectoryUser(parentMyFieldValue))
That was it...thank you Fabio for the explanation. I had tried different combinations to try to get that conversion, but not that one. Above is my Final Code in the Additional Issue Actions in script Post Function
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm happy for that :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fabio,
I am new to Plugin Coding.. that being said does the code reside on .grv file and executed when the transition is executed. Please advice.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fabio,
Does the code reside in file on the JIRA server and called in the post function or where exactly does the code lie. Sorry I am new to plugin/code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I shifted gears a bit and changed what is in Additional Issues actions code:
cfParent = customFieldManager.getCustomFieldObjectByName('Business Owner')
parentMyFieldValue = transientVars["issue"].getCustomFieldValue(cfParent)
log.error("Assign To is \"" + parentMyFieldValue + "\"")
convertedId = getDirectoryUser(parentMyFieldValue)
log.error("Converted to is \"" + convertedId + "\"")
issue.setAssigneeId("OPR0474")
The log file value for parentMyFieldValue is something like opr0474(opr0474). If I could parse out just the opr0474, it works as in the last line when I hard code the value. Is there a function to do this? As you can see I've tried using some functions I've found, but nothing has worked so far.
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.