How to make customField NOT hidden when there is NO value ?

I followed this tutorial and everything is fine.

Only one thing: I would like to have my customField to NOT become hidden when there is NO value.

I tried to work with view.vm:

#if ($value)

// shows the link

#else

<label>Hello the value is Empty!</label>

But nothing shows up. CustomField is still hidden.

Can you please give me some tips about where should I handle this?

I'm working with JIRA 5.1.8

Thanks in advance.

7 answers

1 accepted

This widget could not be displayed.

Ok. I found another solution (to override method getValueFromIssue):

@Override

@Nullable

public String getValueFromIssue(CustomField field, Issue issue) {

// TODO Auto-generated method stub

String value = super.getValueFromIssue(field, issue);

return (value == null) ? "" : value ;

}

just pass whatever value you need and customfield always shows

Just when I needed to do this, I found your answer ;-)

This widget could not be displayed.

Joe has pretty much said a lot of what I would already, so I won't repeat it.

I think you'll need to change code in the core of Jira. The reason is that the framework that draws the screen is making the decision whether or not to render the field, way before you look at the templates. I imagine an internal dialogue like

  • Jira: Oi, field on issue, you got data?
  • Field on issue: Yes
  • Jira: Ok, field definition, how do I draw this?
  • Field definition: here's some velocity and some data, and my display name
  • Jira: There you are user, some nice html with a field name, and some pretty data

And then:

  • Jira: Oi, field on issue, you got data?
  • Field on issue: No
  • Jira: Ok, next field...

That's better than I could explain it :)

Since we're talking about a "custom" custom field, we do have control over "Field on issue: Yes/No" using that getValueFromIssue(..) method in the CFType class by returning a null value for "No" and non-null for "Yes".

But that's not what happens with system fields. All I need is to do what system fields do, but with customization.

This widget could not be displayed.

I got it working!  My company has permitted me to open-source my solution:

https://github.com/theschles/JIRA_ScriptRunner_AlwaysDisplaySelectList

This widget could not be displayed.
Joe Pitt Community Champion Jul 25, 2013

JIRA is setup to not display most fields that don't have values. Your code may never get executed if there isn't a value

is there any way to handle it with javaScript or some other way?

I actualy tried to set e default value, but the field is still hidden.

Unless it's components, or labels, or fix version, or.....

This widget could not be displayed.
Joe Pitt Community Champion Jul 25, 2013

If it has a default value and still hidden there is another problem. Make sure it is in the on the screen (at least view) and is defined to be available for the issue type/project

actually I've already checked and it's not on the view-issue-screen html page. as soon as there is no value the <div> for custom field disappears.

but it is assigned to Default Screen and it show up in Edit and Create Issue (and after adding the value)

This widget could not be displayed.

You can control this from the your CFType class. If the getValueFromIssue method returns null, the velocity file will never get called. You can return an empty string or something to make it look like it has a value and then handle it in the velocity file.

Thanks for advice it actually almost solved everythig, there's just one new problem:

i check the value in getVelocityParameters next way :

if (getValueFromIssue(field,issue)==null)

{

log.warn("Field was empty");

//createValue(field, issue, "Edit");

updateValue(field, issue, "Edit");

}

in both cases (create and update value) the field becomes only visible after the second visit of the view issue page if the issue at first didn't have customField.

do you have any idea how to handle this ?

This widget could not be displayed.

i think as you know, as of now it is not possible to show if the custom fields are empty, fotr this already issue openned with atlassian vote up here

https://jira.atlassian.com/browse/JRA-6697

https://jira.atlassian.com/browse/JRA-2997

for this some patches are released for old versions of jjira but not for latest version, just gothrough this link it may help you

https://confluence.atlassian.com/display/JIRACOM/Displaying+Custom+Fields+with+no+value

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

122 views 1 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you