Hello,
I am attempting to use groovy script to assign sub task via post function to specific project role. I am new to groovy script and seems simple enough but my programming experience is limited. I am about 3 months in on a new job with an existing JIRA instance. I recently recieved a ticket stating that a specific workflow was not assigning subtasks properly. checking the post function i see this.
Selected Script: Clones an issue and links. : Clones this issue to another issue, optioninally in another project, and optionally a different issue type.
Additional issue actions:
import com.atlassian.jira.project.Project issue.summary = "Integrate: " + issue.summary Project myProject = issue.getProjectObject() def myLead = myProject.getLead() issue.assignee = myLead def sprintField = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Sprint'} issue.setCustomFieldValue(sprintField, null)
### Result: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: issue for class: Script2
This code seems to attempt to assign the subtask to project lead but the code does not seem to be working at all when I run it through the script runner for testing. I am not sure
The idea is to get this to assign to a different unique project role. Any thoughts on if this is even the right way to persue this goal?
Thanks,
~Jon
We camup with this last night. works like a charm.
import com.atlassian.jira.project.Project
import com.atlassian.jira.ComponentManager
import java.util.Set
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.security.roles.*
issue.summary = "Integrate: " + issue.summary
//Assign to the UX Lead
Project myProject = issue.getProjectObject()
ComponentManager componentManager = ComponentManager.getInstance()
ProjectRoleManager roleManager = componentManager.getComponent(ProjectRoleManager.class)
ProjectRole role = roleManager.getProjectRole("UX Lead")
ProjectRoleActors actors = roleManager.getProjectRoleActors(role, myProject)
Set<ApplicationUser> users = actors.getApplicationUsers()
ApplicationUser user = users.iterator().next()
issue.assignee = user.getDirectoryUser()
//Add to the current sprint
def sprintField = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Sprint'}
issue.setCustomFieldValue(sprintField, null)
Hi Jon, we are having the same problem here when we try to assign the issue to a user retrieved from a custom field using Groovy script in a workflo post function. Can you let me know what is the jira/script runner version you are using? thx We are on JIRA 6.4.5/SR 3.0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My boss and I came up with this last night, mostly my boss. Works like a charm. Hope others can use it as well.
import com.atlassian.jira.project.Project
import com.atlassian.jira.ComponentManager
import java.util.Set
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.security.roles.*
issue.summary = "Integrate: " + issue.summary
//Assign to the specific role
Project myProject = issue.getProjectObject()
ComponentManager componentManager = ComponentManager.getInstance()
ProjectRoleManager roleManager = componentManager.getComponent(ProjectRoleManager.class)
ProjectRole role = roleManager.getProjectRole("UX Lead")
ProjectRoleActors actors = roleManager.getProjectRoleActors(role, myProject)
Set<ApplicationUser> users = actors.getApplicationUsers()
ApplicationUser user = users.iterator().next()
issue.assignee = user.getDirectoryUser()
//Add to the current sprint
def sprintField = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Sprint'}
issue.setCustomFieldValue(sprintField, null)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yup, that would do it - it'll assign the issue to the first user found in the role of "UX Lead".
That could be a little arbitrary of course (I'm not sure what order it would find multiple users in) and you might want to catch "no one is in the role" explicity, or you might get failed transactions if assignee is mandatory and it can't assign anyone
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can see a couple of things here,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
for each project, we have many roles. Examples are, designers, artists, project lead, teachers, QA Lead, UX Lead etc. For this workflow, once a certain point is reached and the issue is ready for the next phase of work, we close the ticket and it spawns a new ticket assigned to the next specific role in the project.
example, once artists are done working on a specific task they pass the ticket to content integration team.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Context always helps a bit, but I'm still stuck on the problems:
1. Where are you running the script?
2. You can't assign to a role. Only a single person.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1. Running the script in a post function but testing it in "script runner".
2. So in other words I would need to hard code a username ?
thank you for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, ok, well, the script-runner box is lacking the context of an issue, so you may want to try inserting a specific issue into it.
Well, you don't need to hard code a single user name directly. You could do something a bit more clever in the script, like get a list of the users who are currently in that role, look for the last one of them to update the issue and assign it to that person, for example. It just needs to be a person you're assigning it to.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'd start by picking a volunteer and hard coding them in there! Once you can get the main "assign to user" to work, you can add the "work out who" bit later.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.