import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
String user;
def cfManager = ComponentAccessor.getCustomFieldManager();
def cf = cfManager.getCustomFieldObjectByName("Amount");
switch(issue.getCustomFieldValue(cf) as String)
{
case (int)cfValue("Amount") < 500: user = "alfauser";break;
case (int)cfValue("Amount") < 1000: user = "betauser";break;
case (int)cfValue("Amount") < 2000: user = "gammauser";break;
case "4": user = "username2";break;
case "5": user = "username3";break;
}
issue.setAssignee(ComponentAccessor.getUserManager().getUserByKey(user))
Here is the script
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleActors
import com.atlassian.jira.security.roles.ProjectRoleManager
ComponentManager componentManager = ComponentManager.getInstance()
ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager
def String user
def project = issue.getProjectObject()
def int customFieldToCheck = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Amount').getValue(issue)
//set all roles
ProjectRole role1 = projectRoleManager.getProjectRole("Administrators")
ProjectRole role2 = projectRoleManager.getProjectRole("Developers")
ProjectRole role3 = projectRoleManager.getProjectRole("Test Leader")
switch(customFieldToCheck){
case 0..500:
//user = 'user1'
ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(role1, project) // replace role
user = actors.getUsers().toList()?.first()?.name //have to specify first, since actors is an array
break
case 501..1000:
ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(role1, project) // replace role
user = actors.getUsers().toList()?.first()?.name //have to specify first, since actors is an array
break
case 1001..2000:
ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(role1, project) // replace role
user = actors.getUsers().toList()?.first()?.name //have to specify first, since actors is an array
break
default:
break
}
if(user){
issue.setAssigneeId(user)
}
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.
I'm confused.
Where exactly is cfValue declared?
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.
it's built in , but not for custom script.
Are you using this a custom script post-function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yep.
How am I supposed to declare it? let's see if that's the problem here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please exactly specify what you're trying to do and I can help with the script.
Also define the field type
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My goal is to set the assignee depending the value of a field.
Practically, if you have a $500 offer, it requires approval from a line manager, whereas when you have a $10,000 it requires approval from the COO.
I'm trying to set the assignee to be the role member of the COO role if the amount is above 10k.
I have the numeric field named "Amount" that records the amount that the offer is about.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This works. Just get the issue variable and add imports for component accessor.
Also add more cases if desired
def String user
def int customFieldToCheck = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Amount').getValue(issue)
switch(customFieldToCheck){
case 0..500:
user = 'user1'
break
case 501..1000:
user = 'user2'
break
case 1001..2000:
user = 'user3'
break
default:
break
}
if(user){
issue.setAssigneeId(user)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's great! TY!
If I wanted to assign it to role members instead of specific users, is there a way to address it? for example MemberOfRole('Accounting') ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Np (Y)
How would you prioritize in case of multiple members? Would it be the first random ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It would be a single member in each role so I guess it wouldn't matter.
For example the last role member would be the COO, whereas the previous one would be a Product Manager. Let's just name them Role1, Role2, Role3
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.