When a component changes, I want to set the Assignee to the Component Lead using the Behaviours plugin.
I've got code that can find the component lead and sets the Assignee value, but that value is not accepted by Jira.
import com.atlassian.jira.ComponentManager FormField formComponent = getFieldById(fieldChanged) FormField formUserField = getFieldById("assignee") if (formComponent.getValue() != null) { List components = formComponent.getValue() as List componentManager = ComponentManager.getInstance() userUtil= componentManager.getUserUtil() usera = userUtil.getUserObject(components.first().lead) formUserField.setFormValue(usera) }
usera contains the object for the component lead, including username, but the Assignee field doesn't seem to get set properly.
Here are some debugging results from logging the Assignee name before and after trying to set the value.
2014-07-13 12:39:40,838 http-bio-8080-exec-9 DEBUG jmallon 759x2474x1 h8l6ke 147.11.116.32,0:0:0:0:0:0:0:1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [jira.groovy.user.FieldBehaviours] ----------------- assignee: mart 2014-07-13 12:39:40,838 http-bio-8080-exec-9 DEBUG jmallon 759x2474x1 h8l6ke 147.11.116.32,0:0:0:0:0:0:0:1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [jira.groovy.user.FieldBehaviours] ----------------- usera: mart:10000 2014-07-13 12:39:40,839 http-bio-8080-exec-9 DEBUG jmallon 759x2474x1 h8l6ke 147.11.116.32,0:0:0:0:0:0:0:1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [jira.groovy.user.FieldBehaviours] ----------------- assignee: mart 2014-07-13 12:39:40,839 http-bio-8080-exec-9 DEBUG jmallon 759x2474x1 h8l6ke 147.11.116.32,0:0:0:0:0:0:0:1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Returning map: [assignee:[setValue:mart:10000, fieldType:com.atlassian.jira.issue.fields.AssigneeSystemField, displayName:Assignee]] -------------------------- 2014-07-13 12:39:46,738 http-bio-8080-exec-3 DEBUG jmallon 759x2475x1 h8l6ke 147.11.116.32,0:0:0:0:0:0:0:1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [jira.groovy.user.FieldBehaviours] ----------------- assignee: null 2014-07-13 12:39:46,738 http-bio-8080-exec-3 DEBUG jmallon 759x2475x1 h8l6ke 147.11.116.32,0:0:0:0:0:0:0:1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [jira.groovy.user.FieldBehaviours] ----------------- usera: vincenth:10000 2014-07-13 12:39:46,738 http-bio-8080-exec-3 DEBUG jmallon 759x2475x1 h8l6ke 147.11.116.32,0:0:0:0:0:0:0:1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [jira.groovy.user.FieldBehaviours] ----------------- assignee: null 2014-07-13 12:39:46,739 http-bio-8080-exec-3 DEBUG jmallon 759x2475x1 h8l6ke 147.11.116.32,0:0:0:0:0:0:0:1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Returning map: [assignee:[setValue:vincenth:10000, fieldType:com.atlassian.jira.issue.fields.AssigneeSystemField, displayName:Assignee]]
The first set of lines is from when the record is opened for editing. The second are from when the Component is changed. Note that the assignee field is set to null, and not reset despite the value in usera.
When I try to save the record, I get the error shown in the image below. Note that the visible assignee value (name redacted) has not changed.
What am I doing wrong?
Community moderators have prevented the ability to post new answers.
try formUserField.setFormValue(usera.name)
I think there might be an issue setting the value for the assignee field, I'll have a look. Oh yeah, the slight issue is that the display name and avatar is not shown, just the username, but it does work.
Just try on it's own:
getFieldById("assignee").setFormValue("jmallon")
or whatever your username is, and verify that you can submit the issue and then it shows you as the assignee.
That works, but only with my username, not with any other - I think because it's the equivalent of "Assign to me". I tried using usera.name, to no avail.
Version info: Jira 5.2.11, plugin 0.5.3
Side note: is there any way in a Groovy script to do a console.log, so I can debug from the browser and needn't keep reloading the log file?
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just a ping - the Assignee field seems unsettable via Behaviours. Any word on a solution?
We're up to Jira 6.2.6 now, if that helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This defintely works with the latest version, which is Script Runner 3.0.5...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Will 3.0.5 be backported to Jira 6.2.6?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It works fine on 6.2.x, it's just not marked as compatible with 6.2.x yet. For why see here: https://jamieechlin.atlassian.net/wiki/display/GRV/Upgrading+to+3.0#Upgradingto3.0-MarketplaceCompatibility-isitcompatiblewithJIRA6.2?. You can install it through UPM manually, same way as you installed the beta version.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
While I've got you on the line, so to speak, is there a way to generate a console log message rather than a log.debug message? That would make it much easier to debug.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No. I was working on a browser-based log viewer but that's not going anywhere. When working I am tailing the server log in one window, browser in another etc.
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.