Forums

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

¿How to show or hide options from a Form Field with a Scriptrunner Behaviour?

Javier Martinez Caballero
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 12, 2020

Hi, I’m trying to set up a behavior.

I use it to display some options or others in a form field, depending on the request type of the parent task. I have the following script, but I am not able to set the options.


Any ideas or suggestions?

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def issueManager = ComponentAccessor.getIssueManager()


// Obtener el objeto del padre
def parentIssue = underlyingIssue.parentObject
def nombrePadre = parentIssue.getIssueType().getName()

// Obtener el campo select list
def selectList = getFieldById("10370")
log.info "selectList: ${selectList}"

// Obtenemos el id del select list
def customField= customFieldManager.getCustomFieldObject(selectList.getFieldId() as Integer)

def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

def optionsMap

// Logical operations
if (nombrePadre == "ZGE" ){ //|| nombrePadre == "ZSI"
optionsMap = optionsManager.getOptions(config).findAll{

it.value in ["ZPP","ZPA","ZSI"]
}.collectEntries {
[(it.optionId.toString()): it.value]
}

selectList.setFieldOptions(optionsMap)
}

 

 

1 answer

1 accepted

0 votes
Answer accepted
Subrat Mishra
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.
November 23, 2020

Suggest an answer

Log in or Sign up to answer