Set assignee based on custom field user picker value using script runner

Bunty October 1, 2019

Hello All,

How to Set assignee based on User Picker custom field value on workflow transition.

For example: 

  • If S1 Admin(user Picker field) is null, change the assignee to automatic assignee automatically
  • If S1 Admin is not null, change the assignee to S1 Admin

Thanks in advance,

Bunty

1 answer

1 accepted

1 vote
Answer accepted
Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 1, 2019

Hi @Bunty 

 

Try this:

import com.atlassian.jira.component.ComponentAccessor

def cField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("<user picker field name>")
def cFieldValue = issue.getCustomFieldValue(cField)

if(cFieldValue.name == null) {
issue.setAssigneeId('username')
}
if(issue.assignee==null) {
issue.setAssigneeId('username')
}


Regards,

Seba

Bunty October 1, 2019

Hi Seba,

Thanks for the reply.

Script is not working it is showing below error:

L10.PNG

Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 1, 2019

I also got this error but it works. Did you run it?

If it not working please change it a little bit

import com.atlassian.jira.component.ComponentAccessor

def cField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("<user picker field name>")
def cFieldValue = issue.getCustomFieldValue(cField).name

if(cFieldValue == null) {
issue.setAssigneeId('username')
}
if(issue.assignee==null) {
issue.setAssigneeId('username')
}
Like Bunty likes this
Bunty October 2, 2019

Hi Seba,

Thanks a lot. It worked.

Bunty October 2, 2019
import com.atlassian.jira.component.ComponentAccessor

def cField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("<user picker field name>")
def cFieldValue = issue.getCustomFieldValue(cField)

if(cFieldValue == null) {
issue.setAssigneeId('username')
}
if(issue.assignee==null) {
issue.setAssigneeId('username')
}
Eric Sebian January 4, 2023

Hi. I'm trying a variation of the above, but cant get it to work. Can someone show me where I might be getting it wrong?

The custom field name is Responsible CA.



import com.atlassian.jira.component.ComponentAccessor

def cField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Responsible CA")
def cFieldValue = issue.getCustomFieldValue(cField)

if(cFieldValue == null) {
issue.setAssigneeId('username')
}
if(issue.assignee==null) {
issue.setAssigneeId('username')
}
Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 5, 2023

@Eric Sebian what error/results did you get?

Katherine.Ancheta February 22, 2024

Hi Sebastian,

Is there any way to implement this code in an automation? I want to be able to update the assignee field based on a custom field when an issue is created. My scenario is I have service now tickets coming in with a custom field that allows the person opening up the ticket to identify an analyst that they are working with on the issue. That custom field in service now will be fed to a custom field in Jira instead of feeding into the assignee field. Is there a way to implement this code using an automation? 

 

Thanks,

Kathy A

Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 22, 2024

Hi @Katherine.Ancheta 

 

You can achieve this in automation by using branches. Below example rule configuration.

Screenshot 2024-02-23 at 08.37.49.png

Hope that will help you :)

 

Seba

 

Suggest an answer

Log in or Sign up to answer