Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

I want to set a group picker based on a multilevel cascade field

SysAdmin August 29, 2024

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;

}

}

}

1 answer

1 accepted

1 vote
Answer accepted
Tomasz Kowalczyk
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.
August 29, 2024

hi @SysAdmin , it will be easier to help if you could paste error which appears when you start the script

SysAdmin August 29, 2024

Hi @Tomasz Kowalczyk ,

 

Below are the SS.

 

err.pngerr2.png

Tomasz Kowalczyk
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.
August 29, 2024

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?

SysAdmin August 29, 2024

Thanks @Tomasz Kowalczyk ,

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,

Like Tomasz Kowalczyk likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events