Assignee issue based on the Cascading field

Salim Hammar May 12, 2023

Hello

 

I have do a script , he assignee the issue created a user specifis based in custom field cascading field but he don't work

 

Can you help me ?

-----------------------------------------------------------------------------------------

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
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.jira.util.ImportUtils
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser

def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectByName("Applications / Services")
def value = issue.getCustomFieldValue(cField)
//log.warn("la valeur est " + value)

MutableIssue issue = issueManager.getIssueObject(issue.key)
def user = userManager.getUser("login1")
def user1 = userManager.getUser("login2")



if (issue.getCustomFieldValue(cField) == "test42 - testy")
{
 log.warn("the value is " + value)
 issue.setAssignee(user)
 
 log.warn("le ticket a été assigné a " + user)
}
-----------------------------------------------------------------------------------------
Thanks in advance

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 12, 2023

Can you provide more details?

In what context are you running this script? Is it in a custom scripted postfunction, scripted listener or something else?

What type of field is your custom field "Applications / Services"? Is is a single select drop-down? A free text field? An asset field? Something else?

Salim Hammar May 14, 2023

Hello @Peter-Dave Sheehan 

 

Thanks for your answer

 

So this script is a listenner script that will activate when I create a ticket on a jira project.

The field type is a single-choice cascading custom field

cascading.png

 

Thanks in advance

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2023

The getCustomFieldValue method of the issue object, when the custom field is of type cascading select will return a Map with 2 items

[null:ParentOption, '1':ChildOption]

Both the ParentOption and ChildOption will be of type Option.

So if you want to check if a specific combination had been selected, you can do it like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectsByName("Applications / Services")[0]
def optionMap = issue.getCustomFieldValue(cField)
//log.warn("la valeur est " + optionMap)

def user = userManager.getUserByName("login1")
def user1 = userManager.getUserByName("login2")

if (optionMap[null].value == "test42" && optionMap['1'] == "testy") {
log.warn("the value is " + optionMap)
issue.setAssignee(user)

log.warn("le ticket a été assigné a " + user)
}

A couple of notes,

  1. "issue" provided in the listener is already an issue object, there is no need to call issueManager.getIssueObject.
  2. userManager.getUser is deprecated. You should use userManager.getUserByName
  3. In a listener, issue.setXXX will only update the issue in memory. If you want to persist the change, you have to make explicit calls to issueManager.updateIssue. Or skip the setXXX method and use the IssueService instead.

 

 

Suggest an answer

Log in or Sign up to answer