You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
Hi all, I'm using the Scriptrunner post function and i'm trying to set the assignee based on a component and custom field. I understand apart from setting the assignee, you'd also need to store that in the DB. (Currently it doesn't change the value of the assignee). Could anyone help with how to store the assignee? Below is what i have so far
import com.atlassian.jira.component.ComponentAccessor
// the username of the assignee
final String user= "user1"
def user_user1 = ComponentAccessor.userManager.getUserByName(user)
def location = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("Location")
def location_val = issue.getCustomFieldValue(location)
if(issue.components*.name.contains('Hardware') && location_val == "Utrecht" ){
issue.setAssignee(user_user1)
}
You do not need to think about storage or indexing, the post-functions on the transition will do all of that for you, as long as you put your post-function in the right order in the list (it should be done before indexing and store issue)
Your code looks mostly ok to me as well, but I suspect there's a fault in the "if". You are comparing location_val with a string, but that will only work if location_val really is a string. Is the location field really a short text field?
Or is it a select list? If it's a select list, then your "if" is comparing a string with an option, so they're never going to be equal. I would try
&& "Utrecht".equals(location_val.getName()
If it is not that, then I'd guess that your user does not exist, or your feidls do not have the values you are checking for (or do not exist for the project and issue type)
You're spot on about the if statement. The was the issue as the field that i'm referring to is a select field. I tried your method but it kept giving me errors. I've added this line to get the value from a select field:
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Location'}
def cfConfig = cf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Utrecht' }
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.
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.