Hi Script Runner Users,
I'm new to script runner and want to achieve thing which more of people are using (I think at least). Depending on value from custom field the issue should be assigned to different user group.
if system=system1, than assign to system1_approval_group
if system=system2, than assign to system2_approval_group
I found post condition where assignment is to first user of project role. This would be also acceptable but I'm not able to extend this function depending on custom field.
Can someone help me, please?
Thanks a lot and nice regards!
Hi Nic, and can you help me how the condition should look like? Thanks a lot!
Hi,
I do not know much about script runner but JIRA Enhancer Plugin comes with this feature.
http://jiraenhancerplugin.com/documentation.html#assign-to-role-based-on-property-function
Tuncay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nic, yes, it should be first user of group or role. I can paste the code for assigning to 1st person in project role (but without most needed condition - depending on system)
Script Source
package com.onresolve.jira.groovy.canned.workflow.postfunctions
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.util.ErrorCollection
import com.onresolve.jira.groovy.canned.CannedScript
import com.onresolve.jira.groovy.canned.utils.CannedScriptUtils
import org.apache.log4j.Logger
class AssignToRoleMember implements CannedScript {
public static String FIELD_ROLE_ID = "FIELD_ROLE_ID"
def log = Logger.getLogger(AssignToRoleMember.class)
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class)
String getName() {
"Assign to first member of role"
}
String getDescription() {
"Assign to the first member of the specified role"
}
List getCategories() {
["Function"]
}
List getParameters(Map<String, String> params) {
[
[
Label: "Role",
Name: FIELD_ROLE_ID,
Type: "list",
Values: CannedScriptUtils.getAllRoles(false),
Description: "Specify the role the previous assignee must be in",
],
]
}
ErrorCollection doValidate(Map<String, String> params, boolean forPreview) {
null
}
Map doScript(Map<String, Object> params) {
def projectRoleId = params[FIELD_ROLE_ID] as Long
def role = projectRoleManager.getProjectRole(projectRoleId)
assert role // role must be valid
def issue = params["issue"] as MutableIssue
def actors = projectRoleManager.getProjectRoleActors(role, issue.getProjectObject())
def roleUsers = actors.getUsers()
if (roleUsers) {
issue.setAssignee(roleUsers.toList().first())
}
else {
log.warn ("Wanted to set the assignee to a member of the ${role.name} role, but it had no members")
}
}
String getDescription(Map<String, String> params, boolean forPreview) {
def projectRoleId = params[FIELD_ROLE_ID] as Long
def role = projectRoleManager.getProjectRole(projectRoleId)
"Assign this issue to the first member of the <b>${role.name}</b> role"
}
Boolean isFinalParamsPage(Map<String, String> params) {
true
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to insert your code into the "doscript" function
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can't assign an issue to a group. Only to individual users.
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.