Hide components based on issue type

Christian Czaia _Decadis AG_
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.
February 19, 2013

Hi all,

I was wondering if anyone has ever had to hide components based on issue type. I know that this question is most likely a duplicate of https://answers.atlassian.com/questions/128050/how-to-create-components-based-on-issue-type

but I wanted to know if I can hide specific components via Javascript or the behaviours plugin...

Anyone has ever done sth. like this?

Thanks for any hints,

Christian

5 answers

0 votes
M October 30, 2013

Hi guys,

For my case, the subcomponent field does not reflect. Here is my code:

import org.ofbiz.core.entity.GenericValue

import com.atlassian.core.ofbiz.util.OFBizPropertyUtils

public void setSubComponentOptions () {

FormField formComponent = getFieldById(fieldChanged)

FormField formSubcomponent = getFieldById("customfield_10901")

Object componentFormValue = formComponent.getFormValue()

List componentIds = []

if (componentFormValue instanceof List) {

componentIds.addAll(componentFormValue as List)

}

else {

// could be an empty string if all components are deselected

if (componentFormValue) {

componentIds.add(componentFormValue)

}

}

Map fieldOptions = [:]

fieldOptions.put ("-1", "None")

for (Long componentId : componentIds) {

try {

Long.parseLong(componentId)

} catch (NumberFormatException e) {

log.error ("Could not get component Id as Long")

return

}

GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId))

switch (component?.get("name")) {

case "Network Issue" :

fieldOptions.putAll (["11201":"SAP"])

break

}

}

formSubcomponent.setFieldOptions (fieldOptions)

}

Appreciate your help.

Regards,

MG

0 votes
Raju Adluru
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.
August 12, 2013

Jamie

I am using above code to set Custom field - Applications based on Component in JIRA 6.0.2

I am getting below errors: can you pls guide me what could be issue here?

,807 http-bio-9000-exec-19 ERROR 570x161444x1 l5xrx1 197.1.18.83 /secure/QuickCreateIssue.jspa [groovy.canned.utils.ConditionUtils] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script28.groovy: 2: unable to resolve class FormField
@ line 2, column 15.
FormField formComponent = getFieldById(fieldChanged)
^

Script28.groovy: 3: unable to resolve class FormField
@ line 3, column 15.
FormField formApplications = getFieldByName ("Applications")
^

Script28.groovy: 29: unable to resolve class GenericValue
@ line 29, column 22.
GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId))
^

3 errors

M October 30, 2013

Hi Raj,

I presumed you have missed out the imports:

import org.ofbiz.core.entity.GenericValue

import com.atlassian.core.ofbiz.util.OFBizPropertyUtils

0 votes
Mizan
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.
February 19, 2013

Based on issuetype you can set options to the component field , refer this similar example for setFieldOptions() . The map for component field options will contain [id:name]

0 votes
Christian Czaia _Decadis AG_
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.
February 19, 2013

How would I remove them...Maybe you could point me to the right direction. Would that be close to what youre describing in your example

Add or remove options to single or multi-select fields

on your example page?

https://jamieechlin.atlassian.net/wiki/display/JBHV/Miscellaneous+Behaviours+Examples

0 votes
JamieA
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.
February 19, 2013

I think you can... you can remove components from the available selection so you should be able to do that based on issue type.

Suggest an answer

Log in or Sign up to answer