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

Iryna Laryionava July 25, 2013

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

4 votes
Answer accepted
Iryna Laryionava July 28, 2013

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 ;

}

Iryna Laryionava July 28, 2013

just pass whatever value you need and customfield always shows

IshanL
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.
December 15, 2014

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

2 votes
Philip Schlesinger June 1, 2015

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

https://github.com/theschles/JIRA_ScriptRunner_AlwaysDisplaySelectList

2 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 25, 2013

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...
Florin Manaila
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.
July 25, 2013

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".

Iryna Laryionava July 25, 2013

good dialogue =)

Lucid Software October 7, 2014

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

1 vote
Joe Pitt
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 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

Iryna Laryionava July 25, 2013

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)

0 votes
RambanamP
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.
July 26, 2013

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

0 votes
Florin Manaila
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.
July 25, 2013

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.

Iryna Laryionava July 25, 2013

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 ?

0 votes
Joe Pitt
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 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

Iryna Laryionava July 25, 2013

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.

Lucid Software October 4, 2014

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

Suggest an answer

Log in or Sign up to answer