I would like to add a custom value field (a dropdown select box) to show the different teams available, so that the user can select from a controlled list of teams (rather then the Assign box which shows all the users). I then want this to assign the issue to that team.
I have tried using a groovy script as part of the workflow to reassign it to the specific team, but I wasn't able to get it working.
So on my create screen I have a select box with the following;
Network Team
Security Team
Email Team
Scenario example, a user is raising a network problem they select Network Team and the issue is then assigned to the user "Network Team"
First, your code is a listener class, not a postfunction script. Try to use only the code within the method customEvent(IssueEvent event) as your post function.
Second, category will be an Option object if your custom field is a select list. You have to use
def category = issue?.getCustomFieldValue(cfCategory)?.value
to get the selected value.
Oh, thanks Henning, I'd completely missed that!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So this is my new script that I have, but it's still not working, still going to the default;
import java.util.* import java.sql.Timestamp import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.* import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueInputParameters import com.atlassian.jira.issue.link.* import com.atlassian.jira.event.issue.AbstractIssueEventListener import com.atlassian.jira.event.issue.IssueEvent import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.CustomFieldManager import org.apache.log4j.Category import com.atlassian.crowd.embedded.api.User import com.atlassian.plugin.PluginAccessor import com.atlassian.jira.bc.project.ProjectService import com.atlassian.jira.user.util.UserUtil void customEvent(IssueEvent event) { Issue issue = event.issue User user = issue.getAssigneeUser() if (issue.isSubTask()) { return } def customFieldManager = ComponentManager.getInstance().getCustomFieldManager() def cfCategory = customFieldManager.getCustomFieldObjectByName("Team Involved") //use your custom field name here def category = issue?.getCustomFieldValue(cfCategory)?.value def userToReassign = issue.getAssignee() UserUtil userUtil = componentManager.getUserUtil() switch (category) { case "Desktop": <br>userToReassign = userUtil.getUserObject("DesktopSupport")<br>break case "Network": <br>userToReassign = userUtil.getUserObject("NetworkSupport")<br>break } issue.setAssignee(userToReassign) issue.store() }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Now remove the line
void customEvent(IssueEvent event) {
and the closing } and try again.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm now running this, with no luck
User user = issue.getAssigneeUser() if (issue.isSubTask()) { return } def customFieldManager = ComponentManager.getInstance().getCustomFieldManager() def cfCategory = customFieldManager.getCustomFieldObjectByName("Team Involved") def category = issue?.getCustomFieldValue(cfCategory)?.value def userToReassign = issue.getAssignee() UserUtil userUtil = componentManager.getUserUtil() switch (category) { case "Desktop": <br>userToReassign = userUtil.getUserObject("Desktop Support")<br>break case "Network": <br>userToReassign = userUtil.getUserObject("Network Support")<br>break } issue.setAssignee(userToReassign) issue.store()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where in the order of post functions are you doing this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's last in the list of post functions on the Create link between Create and Open processes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, the create transition. Ugh. That thing seems to do horrid things to post-functions sometimes.
Two quick things to try (separately):
1. Remove all the "default assignee" stuff - configure your project so that issues are unassigned by default, rather than project or component leads
2. Move the function up above "re-index" in that order.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tried them, but it's now just raising as 'unassigned'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.option.Option import com.atlassian.jira.user.util.UserUtil import org.apache.log4j.Level import org.apache.log4j.Logger MutableIssue issue ComponentManager componentManager = ComponentManager.instance Logger log log.setLevel(Level.DEBUG) log.debug "Starting postfunction..." if (issue.isSubTask()) { log.debug "Issue is subtask, leaving." return } def customFieldManager = componentManager.getCustomFieldManager() def cfCategory = customFieldManager.getCustomFieldObjectByName("Team Involved") log.debug "Found customfield ${cfCategory}." def category = (issue?.getCustomFieldValue(cfCategory) as Option)?.value log.debug "Got category ${category}." def userToReassign = issue.getAssignee() log.debug "Got assignee ${userToReassign}." UserUtil userUtil = componentManager.getUserUtil() switch (category) { case "Desktop": log.debug "Getting user for Desktop category." userToReassign = userUtil.getUserObject("Desktop Support") break case "Network": log.debug "Getting user for Network category." userToReassign = userUtil.getUserObject("Network Support") break } log.debug "Setting user to ${userToReassign}." issue.setAssignee(userToReassign)
before the "Creates the issue originally". If it doesn't work please post the corresponding log.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Uups, to much.. The first lines are only for the IDE, so they have to be removed, resulting in this.
import com.atlassian.jira.issue.customfields.option.Option import com.atlassian.jira.user.util.UserUtil import org.apache.log4j.Level log.setLevel(Level.DEBUG) log.debug "Starting postfunction..." if (issue.isSubTask()) { log.debug "Issue is subtask, leaving." return } def customFieldManager = componentManager.getCustomFieldManager() def cfCategory = customFieldManager.getCustomFieldObjectByName("Team Involved") log.debug "Found customfield ${cfCategory}." def category = (issue?.getCustomFieldValue(cfCategory) as Option)?.value log.debug "Got category ${category}." def userToReassign = issue.getAssignee() log.debug "Got assignee ${userToReassign}." UserUtil userUtil = componentManager.getUserUtil() switch (category) { case "Desktop": log.debug "Getting user for Desktop category." userToReassign = userUtil.getUserObject("Desktop Support") break case "Network": log.debug "Getting user for Network category." userToReassign = userUtil.getUserObject("Network Support") break } log.debug "Setting user to ${userToReassign}." issue.setAssignee(userToReassign)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
THANK YOU!!!
I had to change the assignee's from "Desktop Support" to "DesktopSupport" for it to pick it up, but it has now.
Perfect :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can you "Copy Value From Other Field Post-Function" from JSU plugin
check this
https://jsutil.atlassian.net/wiki/display/JSUTIL/JIRA+Suite+Utilities+Workflow+Post-Functions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Erm, sorry, no, that's wrong.
That function can only copy between fields of compatible types. e.g. text to text, date to date etc. The request here is to copy an <option> to a <user>, so that's never going to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Nic,
you are wrong!!
it is worked for me, just now i created one select list with by hot coding user names as options and configured "Copy Value From Other Field Post-Function" to copy the selct list field to assignee, it worked like Charm!!
if you want you can check it out ! i tested it on JSU 1.3.5 version
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, it fails miserably in both Jira installs I've tried it in. One of them throws a cast exception when the function executes and the other lets you do it, but you end up with an empty field and an error in the log when the field is rendered.
So, it might work. I've not seen it do so.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
which version of JSU you have tested it on.
i have check the source code and it supporting to copy value from select list to assignee
check the setFieldValue method here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1.3.5 here.
So it works for some installations and not others. Worth a try.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To clarify - is "Network Team" a dummy user as well as a line in your selection list?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, exactly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, that's a good plan, and I think the groovy script is by far the best approach.
I'd say we need to see what code you've got so far, know where it is running (post function?) and details on what is not working with it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's set as a post function in the workflow, and the problem is that it's still assigning the issue to the project lead (me) and not the team selected, I've put the script over at pastebin as it was too big to put here
http://pastebin.com/gPYg6U84
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, your code looks fine to me, although, I'm not 100% sure of this line:
userUtil.getUserObject("Network Support")
Is that definitely returning the user object for the user with that name?
The other question is where the post-function is being run - what is the order of the 5 off-the-shelf postfunctions and this one? I've got a feeling that if it's running too early in that order, then the assignee you set will be overwritten later in the process.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've just dug getUserByName("Dave") out of some of my code, but I think that might be wrong as well, depending on your Jira version.
I'd have a rummage through https://docs.atlassian.com/jira/latest/com/atlassian/jira/user/util/UserUtil.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't know if that line does pull it across, I think this might be my problem.
I've got the line at the bottom of the post functions.
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.