2 May 2012
JIRA: Adding Custom Logic to Custom Fields
by GLiNTECH
Recently there was a requirement in JIRA that a custom field needed to be read-only. This custom field also needed fill based on previous selections which were on the issue edit view. JIRA can be customised by adding Java script and HTML to descriptions on the custom fields. The documentation on this technique can be found here at Atlassian’s website.
Below is an example of what was used to achieve this. This code was inserted into the description section of the customfield_11. The code below sets the default state of customfield_11 to ‘disabled’ and adds a function to the onchange event for the combo boxes that control the values for customfield_11.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
//Get the custom fields objects.
disabledCombo= document.getElementById( 'customfield_11' );
firstCombo=document.getElementById( 'customfield_10' );
secondCombo= document.getElementById( 'customfield_9' );
// Set default state and add onchange functions for the combo boxes
disabledCombo.disabled = 'disabled' ;
secondCombo.onchange= disabledComboOnChangeFn;
firstCombo.onchange= disabledComboOnChangeFn;
function disabledComboOnChangeFn () {
disabledCombo= document.getElementById( 'customfield_11' );
firstCombo=document.getElementById( 'customfield_10' );
secondCombo= document.getElementById( 'customfield_9' );
// Custom logic here. These need to match the values in JIRA combobox values list.
if ( firstCombo.value == 'value1' ){
if (secondCombo.value == 'value1' ){
disabledCombo.value = 'value1' ;
} else if (secondCombo.value == 'value2' ){
disabledCombo.value = 'value2' ;
} else if (secondCombo.value == 'value3' ){
disabledCombo.value = 'value3' ;
} else if (secondCombo.value == 'value4' ){
disabledCombo.value = 'value5' ;
}
}
...
...
...
}
|
Posted by Chris