Forums

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

Custom field java script in JIRA 4.4

Vishnukumar Vasudevan
Community Champion
September 5, 2011

Hi All

Recently I upgraded JIRA 4.1.1 to JIRA 4.4 and started facing some issues with the custom field scripting.

I used control the visibility of the text filed "Blocker Explanation" based on the value of the combo 'priority'. Seems the code doesn't work in JIRA 4.4. Below is the code I used in 4.1.1 ;

---------------------------

<script type="text/javascript">
priority = document.getElementById('priority');
if (priority) {
target = document.getElementById('customfield_10061FieldArea');
// Hide the target field if priority isn't a Blocker
if (priority.value != 1) target.style.display='none';

priority.onchange=function() {
if (this.value == 1) {
target.style.display = '';
} else {
target.value='n/a';
target.style.display='none';
}
}
}
</script>

---------------------------------

Going through some posts, I have tried the below codes too..no luck;

--------------------

<script type="text/javascript">
priority = document.getElementById('priority');
if (priority) {
target = document.getElementById('customfield_10061').parentNode;
// Hide the target field if priority isn't a Blocker
if (priority.value != 1) target.style.display='none';

priority.onchange=function() {
if (this.value == ) {
target.style.display = '';
} else {
target.value='n/a';
target.style.display='none';
}
}
}
</script>

----------------

Do we need to change anything in jira 4.4 ?

Any suggestions would be appricated.

Cheers !!

Vishnu.

1 answer

2 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.
September 5, 2011

Why don't you use jquery as below. Also your 1 should "1" as the priority value is a string.

Not complete example:

(function($){
    $(function(){
        $("#priority").change(function () {
            if ($(this).val() == "1") {
                $("#description").closest(".field-group").show();
            }
            else {
                $("#description").closest(".field-group").hide();
            }
        })
   });  
})(AJS.$);

Vishnukumar Vasudevan
Community Champion
September 5, 2011

Thanks for the suggestion.

In fact priority values are "Blocker" "critical" etc...so if I say 1 thats "Blocker". This is how it worked in 4.1.1

In the above jql how can I assign target and priority ?

Please update that too...

Regards

Vishnu.

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.
September 5, 2011

It's not 1, it's "1". It's the difference between an integer and a string. Javascript will coerce it for you so that's irrelevant anyway.

The above is javascript not JQL. I was only trying to give you a starter for 10, I haven't got time to write it for you completely.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events