The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Groovy Script Error

Jh
Contributor
December 8, 2020

I have a groovy script as a post function and I want to create a Sub-Task depending on whether the value of a custom field is "Yes". It is just a Yes or No custom field type.

Below are what I am currently importing and what my snippet of the script is

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.project.Project
import groovy.transform.Field
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.user.ApplicationUser



// Check for SAP Access
def sapTypeCF = customFieldManager.getCustomFieldObjectByName("Needs SAP Access?")
LazyLoadedOption sapTypeField =(LazyLoadedOption) parentIssue.getCustomFieldValue(sapTypeCF)
def valueOfSAPType = sapTypeField?.getValue()

I get a failed script execution with the error:

2020-12-08 15:20:59,056 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue TPSHR-17868 for user 'Admin'. 
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[Yes]' with class 'java.util.ArrayList' to class 'com.atlassian.jira.issue.customfields.option.LazyLoadedOption' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.issue.customfields.option.LazyLoadedOption(com.atlassian.jira.issue.customfields.option.LazyLoadedOption) at Script61.run(Script61.groovy:57)

 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
PD Sheehan
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 Champions.
December 8, 2020

Base on the error, my guess is that your custom field is either Checkbox or Multi-Select.

This means that result of getCustomFieldValue is an AarrayList<LazyLoadedOption> rather than a single LazyLoadedOption

What you can try instead is something like this:

def sapTypeCfValues = parentIssue.getCustomFieldValue(sapTypeCF)
def sapTypeYes = sapTypeCfValues.any{it.value == 'Yes'}

Jh
Contributor
December 8, 2020

Ahh I see, small mistake on my side. The original custom field is a Select List type and I created the new custom field as a Checkbox. I just deleted it and re-created it as Select List and it worked now.

DEPLOYMENT TYPE
SERVER
VERSION
8.13.1
TAGS
AUG Leaders

Atlassian Community Events