Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Auto Assignation Based on A Custom Field which is Select List (Cascading)

Priscilla Achampong July 1, 2019 edited

Hi, 

Having an issue with a similar code.

It's not auto assigning issues on creation using "Custom script post-function (inline script)" in the workflow post function.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.crowd.embedded.api.User

String user;

def cfManager = ComponentAccessor.getCustomFieldManager();
def cf = cfManager.getCustomFieldObjectByName('field name');

switch(issue.getCustomFieldValue(cf) as String){
case 'value 1': user = "email address";break;
case 'value 2': user = "email address";break;
}

issue.setAssignee(ComponentAccessor.getUserManager().getUserByKey(user))  

 

However, results display confirmation copy of no failures:

 

chrome_bumOiNiDOC.png

 

I'm working within JIRA upgraded version 7.13.2.

Would it be possible for someone to provide advice on how to fix this?

 

Also, legacy script for auto-assignation is not working when placed in a new workflow, even though I've updated relevant custom fields and reference links. Does anyone know why this would be happening?

 

Thanks.

1 answer

0 votes
fjodors
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2019

Hi

Have you tried to enable log? (see this article for details https://community.atlassian.com/t5/Jira-questions/Autocompletion-today-s-date-in-transition-Scriptruner/qaq-p/1110198#M353669)

From your code looks like your are using emails, not keys or usernames.
Try to use key/name instead of email, from jira api

getUserByKey(String userKey)
Returns an ApplicationUser based on user key.

getUserByName(String userName)
Returns an ApplicationUser based on user name.

 

Example:

user = "name.surname"
issue.setAssignee(ComponentAccessor.getUserManager().getUserByKey(user))
Priscilla Achampong July 2, 2019

Hi Fyodor,

Thanks for suggesting the log and code updates. I can confirm the code works without the log and with email addresses. What seems to be happening is the custom field selected isn't working.

I've changed my target field to be one which is a Select List (single choice). This is showing that using a two tier list is causing the issue.

Do you know how to format the code to apply to custom fields which type is Select List (cascading)?

Thanks

Suggest an answer

Log in or Sign up to answer