I'm looking to have a post function assign a JIRA issue depending on two fields that are of the single select type (Region and Network). Although the JIRA in question has both fields set with values that are described in the IF statement the user assigned is userB. Is there something I'm missing in the script below?
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
//define custom field manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
//define custom fields
def Network = customFieldManager.getCustomFieldObject("customfield_10742")
def Region = customFieldManager.getCustomFieldObject("customfield_14440")
def userA = ComponentAccessor.userManager.getUserByName("John")
def userB = ComponentAccessor.userManager.getUserByName("Maria")
if(Network == "Airport"){
issue.setAssignee(userA)
}
else{
issue.setAssignee(userB)
}
Your def Network and def Region lines are not doing what you think. The variables will contain the objects representing the custom fields, not the content of them.
It's also quite likely that even if you do get the values, the if ( == ) bit won't work - if the fields are select lists, the content of the fields will be Jira "options" not strings. If that's the case, then you'll want something more like
if ("Airport".equals(networks-value.getName() )
https://library.adaptavist.com/entity/update-priority-based-on-a-custom-field has some sample code about working with custom fields.
Nic, thanks for the explanation and link to examples it really helped! After applying the changes the assignee is being assigned to the correct user based on the contents of the designated custom fields. I'm still a bit green when it comes to creating custom scripts with ScriptRunner, is there a recommended resource you can point me to for learning the ins and outs of it?
Again, thanks for taking the time to answer this for me, truly appreciate it!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tend to steal a lot from the Library, even the scripts I've written that have made it in there!
But for getting started, I'd skim through the resources at https://docs.adaptavist.com/sr4js/latest
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.