I want to set a group picker based on a multilevel cascade field
Asked by SysAdmin:

Hi,

I want to set a group picker based on a multilevel cascade field using script listener for Issue created and Issue updated events.

The script is throwing error in compilation 'cannot find matching method'

Need help to trouble shoot this.

The script is as below

```
import java.util.ArrayList

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.event.type.EventDispatchOption

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.issue.ModifiedValue

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

import com.atlassian.jira.issue.customfields.option.Option

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.issue.customfields.option.LazyLoadedOption;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

CustomField customField = customFieldManager.getCustomFieldObjectByName("Categories");

CustomField assignedGroup = customFieldManager.getCustomFieldObjectByName("Assigned");

//def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("abc-3")

def cfVal = issue.getCustomFieldValue(customField) as ArrayList; 

log.warn "cfValue "+cfVal

def groupManager = ComponentAccessor.getGroupManager()

if(cfVal.size()>1){

def firstLevel = cfVal.getAt(0) as com.atlassian.jira.issue.customfields.option.LazyLoadedOption

log.warn" first level "+firstLevel 

if(firstLevel.getValue() in ["Brokerage","Asset Management","Compliance","Legal", "Super App","HR/Finance","External Channels","Core/Supporting Services","Institutional Custody","Digital Supporting Services","Research"] ){

log.warn "value present "

switch(firstLevel.getValue()){

case "Brokerage":

    

    def group= groupManager.getGroup("L2-Brokerage")

    assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

    break;

case "External Channels":

    if(cfVal.size()>=2){

        def secondLevel = cfVal[1] as com.atlassian.jira.issue.customfields.option.LazyLoadedOption

        if(secondLevel.getValue()=="SuperAPP"){

            def group= groupManager.getGroup("L2-Integration")

        assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

   

        }else if(secondLevel.getValue() in ["WeZ portal"]){

            //L2-Internal

             def group= groupManager.getGroup("L2-Brokerage")

        assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

   

    }

    }      

    break;

case "Core/Supporting Services":

    

    def group= groupManager.getGroup("A_Support")

    assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

    break;

case "Institutional Custody":

    

    def group= groupManager.getGroup("L2-Internal")

    assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

    break;

case "Digital Supporting Services":

    

    def group= groupManager.getGroup("L2-Integration")

    assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

    break;

case "Asset Management":

                //L2-Asset

         def group= groupManager.getGroup("L2-Asset")

        assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

   

    break;

case "Compliance":

    if(cfVal.size()>=2){

        def secondLevel = cfVal[1] as com.atlassian.jira.issue.customfields.option.LazyLoadedOption

        if(secondLevel.getValue()=="KYC"){

            def group= groupManager.getGroup("L2-Internal")

        assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

   

        }else if(secondLevel.getValue() in ["Compliance","Management System"]){

            //L2-Internal

             def group= groupManager.getGroup("L2-Internal")

        assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

   

    }

    }      

    break;

case "Legal":

                     def group= groupManager.getGroup("L2-Internal")

        assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

   

    break;

case "HR/Finance":

               //ARB

                def group= groupManager.getGroup("AB")

        assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

   

 

    break;

case "Super App":

        def group1= groupManager.getGroup("L2-BO")

        assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group1] as ArrayList), new DefaultIssueChangeHolder());

    

    if(cfVal.size()>=2){

            log.warn ""+ cfVal[1].class

        def secondLevel = cfVal[1] as com.atlassian.jira.issue.customfields.option.LazyLoadedOption

        if(secondLevel.getValue()=="Digital"){

           def group= groupManager.getGroup("A_Support")

        assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

    

        }

      else {

        def group= groupManager.getGroup("L2-Integration")

        assignedGroup.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(assignedGroup) as ArrayList, [group] as ArrayList), new DefaultIssueChangeHolder());

    

    }     

    }

     

    

          

    break;

} 

}

}
```


Answers:
author: Tomasz Kowalczyk
body: hi [@SysAdmin](/t5/user/viewprofilepage/user-id/3609486) , it will be easier to help if you could paste error which appears when you start the script

comments: author: SysAdmin
body: Hi [@Tomasz Kowalczyk](/t5/user/viewprofilepage/user-id/3784490) ,

Below are the SS.

![err.png](https://community.atlassian.com/t5/image/serverpage/image-id/344487i5E5F8F7DC2706439/image-size/large?v=v2&px=999 "err.png")![err2.png](https://community.atlassian.com/t5/image/serverpage/image-id/344488i4BCF7E7B5D41601C/image-size/large?v=v2&px=999 "err2.png")


author: Tomasz Kowalczyk
body: this error shows beacuse you do not have variable issue declared. You can add   
def issue = event.issue but i don't think that's a problem. Could you show us log when listener starts and fails?


author: SysAdmin
body: Thanks [@Tomasz Kowalczyk](/t5/user/viewprofilepage/user-id/3784490) ,

That resolved it, because it started working post declaring it.

Below are the logs

2024-08-29 14:41:48,793 WARN \[runner.ScriptBindingsManager\]: cfValue \[ACC, REna, concile\]  
2024-08-29 14:41:48,793 WARN \[runner.ScriptBindingsManager\]: first level ACC  
2024-08-29 14:41:48,793 WARN \[runner.ScriptBindingsManager\]: value present

Regards,


Tags: data-center

jira

jira-service-management

jira-service-management-data-center