Getting error in the Behaviour (Initiliser)

Nikhil Patil
Contributor
March 5, 2024

We have recently performed the Jira upgrade from JSM version 4.13.3 to JSM version 5.4.15. In which we are having CWISS project, which has two issue types i.e., Incident (INC) and Service request (SR).
Under CWISS project, INC issue type we are having different status for e.g., Implementation is in progress and Assign to.
In the initiliser, we are fetching some values and fields from the current issue and also In the behaviour (Initiliser), depending upon the transition ID in the workflow, we are removing some options from the INC Category custom field.
(i.e., for e.g while transferring the ticket from "Assign to" to "Implementation is in progress" --> we are removing same option from INC category)
But we are getting error in the logs of Initiliser script for the 28th line of the initiliser script.
Please let us know how we can resolve this error.
I have attached the error and also the please find below the 28th line from the script for which we are getting error and Also I have attached the initiliser script for your reference.

def currentIssue = ComponentAccessor.getIssueManager().getIssueObject(Long.parseLong(id.getValue() as String))


Error in logs :
2024-03-04 11:00:42,160 ERROR [behaviours.BehaviourManagerImpl]: *************************************************************************************
2024-03-04 11:00:42,181 ERROR [behaviours.BehaviourManagerImpl]: Script function failed on issue: (create issue) project/issuetype: UCWISS/Incident, user: nikhil, fieldId: __init__, file: <inline script>, edit behaviour: http://jiraaput/plugins/servlet/scriptrunner/admin/behaviours/edit/1601dd66-b769-4789-b99b-c59887a5dee0
java.lang.NumberFormatException: null
at 380d5832672ff62d7a4952aa0e36e7ff.run(380d5832672ff62d7a4952aa0e36e7ff.groovy:28)



Initiliser Script :

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.customfields.option.Option
 
//if (underlyingIssue){
 
def id = getFieldById("id")
 
// Get default options
def selectListField = getFieldById("customfield_10301")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def selectListCustomField =customFieldManager.getCustomFieldObject(selectListField.getFieldId())
def fieldConfig = selectListCustomField.getRelevantConfig(getIssueContext())
def options1 = optionsManager.getOptions(fieldConfig)*.value
 
def Reamrks = getFieldById("customfield_13000")
def DeployCRNo = getFieldById("customfield_14700")
def SLAbreach = getFieldById("customfield_14400")
def ReopenReason = getFieldById("customfield_14200")
def Techcode = getFieldById("customfield_11621")
//25 April 2023 def TicketType = getFieldById("customfield_15800")//Ticket type field 19 April 2022
ReopenReason.setHidden(true)
Reamrks.setHidden(true)
DeployCRNo.setHidden(true)
    def currentIssue = ComponentAccessor.getIssueManager().getIssueObject(Long.parseLong(id.getValue() as String))
    def fieldConfig1 = customFieldManager.getCustomFieldObject("customfield_11621").getRelevantConfig(getIssueContext())
    def options = ComponentAccessor.getOptionsManager().getOptions(fieldConfig1)
    def selected1 = ["-1" : "None"]
String reporterCode1
   String reporterCode = currentIssue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11601")) as String
// In the above line of code we are fetching the reporter office code
 
String Technician_Office_Code = underlyingIssue?.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11621")) as String
//In the above line of code we are fetching the technician office code from the current issue.
 
String No_ofTimesReopen = currentIssue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11102")) as String
//In above line of code we are fetching the count of no. of times reopen ticket
 
    log.error("---------------"+underlyingIssue)
    log.error("---------------"+currentIssue)
    if(!reporterCode.trim().equals("ABCD")){
        reporterCode1 = reporterCode.substring(0, 2) + "0000"
    }
////In above If condition we are checking the first two digit of reporter office code, If the reporter office code is not equals to ABCD then some of the options we are hidding/removing for the specific transitions

//In the below code if the below transition is performed, we are removing some options
if(getAction()?.getId() == 171 ){
        Techcode.setFormValue(" ")
        
    options1.remove("Helpdesk")
    options1.remove("Core L1 support")
    options1.remove("Infra Tools")
 
    // selectListField.setFieldOptions(options1)
        def newOptions = optionsManager.getOptions(fieldConfig).findAll { it.getValue() in options1 }
selectListField.setFieldOptions(newOptions)
        //def optionstosel = options.findAll {it.toString() in ["ABCD","100000",reporterCode1]}
        def optionstosel = options.findAll {it.toString() in ["100000",reporterCode1]}
        selected1 += optionstosel.collectEntries{
            [(it.optionId.toString()) : it.value]
        }
        getFieldById("customfield_11621").setFieldOptions(selected1)
    }
 
//Same in the below code, when we are performing some transitions in the workflow we are removing some options.
else if (getAction()?.getId() ==251 || getAction()?.getId() ==271 || getAction()?.getId() ==351){
     
    options1.remove("Helpdesk")
    options1.remove("Core L1 support")
    options1.remove("Infra Tools")
     //selectListField.setFieldOptions(options1)
     def newOptions = optionsManager.getOptions(fieldConfig).findAll { it.getValue() in options1 }
selectListField.setFieldOptions(newOptions)
        def optionstosel = options.findAll {it.toString() in ["100000",reporterCode1]}
        selected1 += optionstosel.collectEntries{
            [(it.optionId.toString()) : it.value]
        }
        getFieldById("customfield_11621").setFieldOptions(selected1)
    }else if( getAction()?.getId() == 241 ||getAction()?.getId() == 201 ){
        def optionstosel = options.find {it.toString() in ["ABCD"]}
       /* selected1 += optionstosel.collectEntries{
            [(it.optionId.toString()) : it.value]
        }*/
        getFieldById("customfield_11621").setFormValue(optionstosel.optionId)
        Techcode.setReadOnly(true)
    }
 
//Same in the below code, when we are performing some transitions in the workflow we are removing some options.
 
else if(getAction()?.getId() == 191 || getAction()?.getId() == 261  ){
    
    options1.remove("Helpdesk")
    options1.remove("Core L1 support")
    options1.remove("Infra Tools")
     //selectListField.setFieldOptions(options1)
    def newOptions = optionsManager.getOptions(fieldConfig).findAll { it.getValue() in options1 }
selectListField.setFieldOptions(newOptions)
        def optionstosel = options.find {it.toString() in ["ABCD"]}
       /* selected1 += optionstosel.collectEntries{
            [(it.optionId.toString()) : it.value]
        }*/
        getFieldById("customfield_11621").setFormValue(optionstosel.optionId)
        Techcode.setReadOnly(true)
    }else{
        selected1 += options.collectEntries{
            [(it.optionId.toString()) : it.value]
        }
        getFieldById("customfield_11621").setFieldOptions(selected1)
    }
            log.error("-------------------"+fieldConfig1)
//Ticket type field 19 April 2022
 
// if(getAction().getId() == 11)
 
if(getAction()?.getId() == 201){
def optionstosel = options.find {it.toString() in ["ABCD"]}
    options1.remove("Quality")
    options1.remove("Lower Environment Downtime")
     //selectListField.setFieldOptions(options1)
    def newOptions = optionsManager.getOptions(fieldConfig).findAll { it.getValue() in options1 }
selectListField.setFieldOptions(newOptions)
       /* selected1 += optionstosel.collectEntries{
            [(it.optionId.toString()) : it.value]
        }*/
        getFieldById("customfield_11621").setFormValue(optionstosel.optionId)
        log.error("---------------------------------"+optionstosel.optionId)
        Techcode.setReadOnly(true)
    }
        if( getAction()?.getId() == 221){
         if(Technician_Office_Code=="ABCD".trim() &&  No_ofTimesReopen !="0.0".trim()){
//In the above transition if the Technician office code is ABCD and no. of times reopen is not equal to 0 we are adding the below options on the screen 
            log.error("Reopen reason"+No_ofTimesReopen)
            Reamrks.setHidden(false)
            ReopenReason.setHidden(false)
            ReopenReason.setRequired(true)
            DeployCRNo.setHidden(false)
            Reamrks.setRequired(true)
              //
         // TicketType.setHidden(false)
    // TicketType.setRequired(false)
        }
         else{
            Reamrks.setHidden(false)
            ReopenReason.setHidden(true)
            ReopenReason.setRequired(false)
            DeployCRNo.setHidden(false)
            Reamrks.setRequired(true)
            //
            //TicketType.setHidden(false)
    //TicketType.setRequired(false)
        }
    }
else{
    Reamrks.setHidden(true)
    ReopenReason.setHidden(true)
    DeployCRNo.setHidden(true)
     Reamrks.setRequired(false)
    ReopenReason.setRequired(false)
    //
   // TicketType.setHidden(true)
   // TicketType.setRequired(false)
}
 
/*if(getAction().getId() == 141){
        if (Technician_Office_Code=="ABCD".trim()){
            log.error("Office Code"+Technician_Office_Code)
            ReopenReason.setHidden(false)
            ReopenReason.setRequired(true)
        }
    }
else{
    ReopenReason.setHidden(true)
            ReopenReason.setRequired(false)
}*/
 
 
           
 
 
/* if(getAction().getId() == 31 || getAction().getId() == 81){
        if (Technician_Office_Code=="ABCD".trim()){
            log.error(" SLA breached reason Office Code"+Technician_Office_Code)
            SLAbreach.setHidden(false)
        }
    }
else{
    SLAbreach.setHidden(true)
}*/
//}

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events