Forums

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

Need help editing code, when i execute the code getting error like this :java.lang.NullPointerExcept

jirareddy 321 March 8, 2023

We have a requirement based on two custom fields.DAP reason (multi level cascading field) and reason code (single option selection field).

When selecting reason code values ​​for Dropped Duplicate, Duplicate, cannot be tested in Create screen, DAP reason value should be "Not Applicable".

Please find the below code.

 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def ReasonCode = getFieldById(fieldChanged)
def ReasonCodeValue = ReasonCode.value.toString()

def DAPReason = getFieldByName("DAP Reason")

def optionManager = ComponentAccessor.optionsManager
def customFieldManager = ComponentAccessor.customFieldManager

def DAPReasonCustomField = customFieldManager.getCustomFieldObject(DAPReason.fieldId)
def DAPReasonConfig = DAPReasonCustomField.getRelevantConfig(issueContext)
def DAPReasonOptions = optionManager.getOptions(DAPReasonConfig)

def DRNewOptions

if(ReasonCodeValue == "Dropped - Duplicate") {
    DRNewOptions = ["Not Applicable"]
} else if(ReasonCodeValue == "Duplicate") {
    DRNewOptions = ["Not Applicable"]
} else if(ReasonCodeValue == "cannot be tested") {
    DRNewOptions = ["Not Applicable"]

} else {
    DRNewOptions = ["Requirement", "Design", "coding", "Not Applicable"]
}



def DRNewOptionsMap = [null: "None"]

DRNewOptionsMap += DAPReasonOptions?.findAll {

    it.value in DRNewOptions
}?.collectEntries {
    [ (it.optionId.toString()) : it.value ]
}

DAPReason.setFieldOptions(DRNewOptionsMap)



1 answer

0 votes
Tuncay Senturk _Snapbytes_
Community Champion
March 14, 2023

Hi @jirareddy 321 

Welcome to the Community!

Could you please attach the error stacktrace you're getting? 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.13.22
TAGS
AUG Leaders

Atlassian Community Events