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

Determine if "Automatic" was choosen for assignee within workflow validator

Henning Tietgens
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.
September 23, 2012

Hi,

some of our users would like to have a workflow where the user can select an assignee while creating an issue and if not, the issue should be assigned to the current user. For this I'm thinking about writing a workflow validator Groovy script to validate if for assignee "Automatic" was choosen and if this is the case the assignee should be set to the current user.

What I didn't get is, how to get the value of the assignee field of the create screen.

issue.assignee is set to the resulting assignee if automatic is choosen, so this is not an option.

Did some have an idea how to get the assignee field value from the create screen from a validation script? Or maybe, any other idea to achieve the described behaviour?

Thanks,

Henning

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Florin Manaila
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.
October 18, 2012

You can inspect the HTTP request for the "assignee" parameter. A null value = unassigned and a value of -1 = Automatic (which is what you want).

I haven't used groovy runner so I can't say if it can do this, but it can definitely be done if you write your own post-function.

Hope that helps.

Henning Tietgens
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.
October 18, 2012

Ok, thanks. Are these informations part of the params for the AbstractJiraFunctionProvider.execute() method call? Or were do I get the HTTP request?

Henning

Florin Manaila
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.
October 18, 2012

This should do the trick:

webwork.action.ActionContext.getRequest().getParameter("assignee")

Henning Tietgens
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.
October 18, 2012

And were do I get the webwork object? Sorry for all this questions...

Henning

Florin Manaila
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.
October 18, 2012

ActionContext is a static class

Henning Tietgens
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.
December 19, 2012

Ok this works. For everyone who's interested:

Condition:

// Test if assignee is automatic
webwork.action.ActionContext.getRequest().getParameter("assignee") == '-1'

Script:

issue.assignee = currentUser

Thanks for the help

Henning

1 vote
Bhushan Nagaraj
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.
October 15, 2012

Hi Henning,

You can write a workflow post-function which basically does this:

1. If "Assignee" is set to a user other than the current user, dont change anything.

2. If "Assignee" is not set or null, assign it to current user.

Henning Tietgens
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.
October 15, 2012

Ok, thanks. Do you know a way to do this if the Default Assignee is set to Project Lead?

0 votes
Tony Filipe December 17, 2013

Putting it all together for completeness:

import com.atlassian.jira.issue.MutableIssue
import webwork.action.ActionContext


if (ActionContext.getRequest().getParameter("assignee") == '-1')
	issue.assignee = issue.reporter

This worked for me as a Script Validation using the Script Runner plugin on Jira 6.

Chuck Bishop January 13, 2014

I've tried the suggestions on this thread, but none seem to work for me within Script Runner on JIRA 6.x. I would simply like to set a specific user not the default Lead if the user doesn't specify an Assignee (i.e. they leave it set to Automatic). It works if I specify the Value type: 'Raw Value' with the Value set to the desired username. However, when I enable the 'Conditional execution check-box', to only run the script if the Assignee is left as 'Automatic', but it doesn't work. I've enabled logging, but I never seem to get anything useful. Any suggestions?

Thanks

Christoph N_ January 23, 2015

This script has to be added as "Script Validator" under Validators. It is not a Post Function. Works for me in JIRA 6.1. Here's the modified code: {code} import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import webwork.action.ActionContext if (ActionContext.getRequest().getParameter("assignee") == '-1') issue.assignee = ComponentAccessor.getUserUtil().getUser('someuser') {code}

0 votes
neil1967 July 4, 2013

I've turned off Unassigned as a selection in the Assignee dropdown, and now would like to assign to the reporter if Automatic is chosen or left by default. I have tried to use the code talked about here in my groovy script:

webwork.action.ActionContext.getRequest().getParameter("assignee")

but the value is always null, regardless of whether I choose Automatic or an actual user. What am I doing wrong?

Simonas Tvirbutas November 7, 2013

I ran into this as well - looks like there's a bug in the wrapper. Here's how I worked around it:

String assigneeFormValue = ((String[])webwork.action.ActionContext.getRequest().getParameterMap().get("assignee"))[0];

Like Pavels Avens likes this

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events