Forums

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

How to hide customfield unconditionally in jira using JS ?

Egor Erofeev July 13, 2018

Hello,

Very simple question, but I've been struggling with it for several hours already. 

I want to hide one custom field from all screens using JS.

Here is fragment of atlassian-plugin.xml:

<web-resource key="S" name="S" ><resource type="download" name="a.js" location="js/a.js" />
<context>jira.view.issue</context>
</web-resource>

My JS  a.js:

AJS.toInit(function(){
alert("Hello World");
AJS.$('#customfield_10120').closest('div.field-group').hide();

});

 I've read dozens of corresponding forum's questions&solutions but nothing worked for me, field is not hidden.

What I'm missing?

Thanks in advance!

2 answers

1 accepted

0 votes
Answer accepted
Egor Erofeev July 16, 2018

Finally I was able to resolve this riddle. The working js template is 

AJS.toInit(function(){

var hideField = "#customfield_10121";
var elem = $(hideField + "-val");
var parent = elem.parent();
parent.remove();
}); 

CF 10121 has successfully been hidden. 

Egor Erofeev July 16, 2018

Just in case someone needs: how to inject vars from Java class to JS inside velocity template:

#set ($CustomField=$CF)


<script type="text/javascript">
AJS.toInit(function(){
var hideField = "#" + "${CustomField}";

...
0 votes
Egor Erofeev September 6, 2018

Unfortunately, custom field is not hidden, when issue is opened in Search query, but hidden when displayed as jira/browse/PRO1-1:

image.png

 

 

If someone know how to hide it (using js) in Search view, please, help.

Regards.

Suggest an answer

Log in or Sign up to answer