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;
}
}
}
hi @SysAdmin , it will be easier to help if you could paste error which appears when you start the script
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.