Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Using Behaviours plugin to set assignee from component lead

Joe Mallon
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 13, 2014

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?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 14, 2014

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.

Joe Mallon
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 14, 2014

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.

Joe Mallon
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 26, 2014

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.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 26, 2014

This defintely works with the latest version, which is Script Runner 3.0.5...

Joe Mallon
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 26, 2014

Will 3.0.5 be backported to Jira 6.2.6?

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2014

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.

Joe Mallon
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2014

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.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 31, 2014

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.

TAGS
AUG Leaders

Atlassian Community Events