Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to check condition and display in Jira 5.0 velocity files ?

I have a select list and by default it's value is "Please select" but while displaying I want to display "Null" instead of " Please select ". I have attched the screenshots and the velocity file code. I am not sure what i am doing wrong ?

Screenshot while creating the issue

#customControlHeader ($action $ $ $fieldLayoutItem.required $displayParameters $auiparams)
<select class="select" name="$" id="$">    
     #foreach ($option in $configs.options)
        #if(!$option.disabled || $option.disabled == false || ($value && $value == $option.optionId.toString()))
          #if ($value && $value.equals($option.optionId.toString())) #set ($selected = ' selected="selected"') #else #set ($selected = '') #end
            #if ( $selected == $option.optionId.toString() )
               <option selected="selected" value=$option.optionId.toString()>$option.toString()</option>
                <option value=$option.optionId.toString()>$option.toString()</option>
#customControlFooter ($action $ $fieldLayoutItem.fieldDescription $displayParameters $auiparams)

#if($value == 'Please select') || $option.equals("Please select"))
    #set ($value = 'Null')

Screenshot after submitting the issue

1 answer

0 votes

This looks a little confused to me.

"Please select" should not appear on a "view" screen, unless you've deliberately added it as an option to the list of options, and someone has selected it. If that is the case, then do the simple thing - rename the option to "Null" and it'll all work fine. (Although, if your users are English speaking, and non-technical, I really would avoid using the word "null", it's not very helpful for non-techies)

If my assumption there is wrong, then I'd have to question why and how you've got "please select" appearing at all?

I also think your velocity may be faulty - $value *might* be a string (so == won't work on it), but you can check your java to confirm that.

Yes, "Please select" should not appear on a "view" screen even if you selected as an option.

I did add Please select as an option but if the user selects "Please select" I want to display null or n/a instead of "Please select".

I did also tried this condition

#if($value.equals("Please select") || $option.equals("Please select"))

Um, that sounds immensely broken to me. "Please select" simply is not a sane option to have in your data - it's self-contradictory (even if you output "null", it's still wrong). Your data will actively contain "please select" implying the users have made an active choice to select "please select" as an option.

Can you explain exactly why you've done this - what are you trying to achieve? I can't think of a scenario where adding a "please select" option is a valid approach, but I'm not very imaginitive.

(I actually think I already know what you're trying to do, and there's a far better way to do it, but I don't want to chase the wrong answer if I'm guessing inaccurately)

The inbuilt select list consists of None value and we don't want that. We don't want to make that as a required field . we already have many projects in Jira and I don't want to remove none option in velocity file, which reflects entire jira instance projects. I want to develop a select list plugin without none option and also at the same point of time if the user doesn't select anything i want to display as N/a or null. I also want to increase the width of the select list in this plugin.

hmm. I am not sure if i confused you. If the user selects "please select" option then it has to display as "N/A".

Ok, that's roughly what I thought, but with a couple of extra tweaks.

First, you really do need to kill off "please select" as an option, it's pointless complexity and functionally useless.

Second, think through and decide what you actually want, because this statement is self-contradictory, you can do one or the other, but not both.

> want to develop a select list plugin without none option and also at the same point of time if the user doesn't select anything i want to display as N/a or null

Either you want to display something, or you don't. If you remove "none", then there's nothing TO display as NA/null/None/Please-select/etc. Decide whether you want:

  1. a select list that doesn't display any options for "no data"
  2. a select list that displays something to the user to tell them "no data" and will not store anything if selected (for example, showing "none" as an option...).

Note that in both cases, I'm skipping the question of mandatory entry, as it's not important to the display, it's up to you to decide whether the users can skip it (although it sounds like you'll always set it)

Now, I understand you need to do this on a by-project basis, so you've got two approaches here as well.

  • Either hack the global options as you've already found - for this case, you'll want to have "if project X, then use behaviour 1, if project Y, use behaviour 2" type statements in it. That sounds clunky to me, but does save you writing an entire field plugin
  • Write a plugin as you say. Then you can do what you want with the "no data" option when it's used in the velocity.

Nope, not confused about what you are trying to do. I'm confused about your approach - you seem to be making it hideously complex, breaking your data, and bodging around it.

The fix boils down to:

  1. "please select" should be removed, excised, deleted, expunged, got rid of. Adding fundamentally broken data is the worst possible approach to this problem, as you then have to do a lot of coding to plaster over an obvious bodge.
  2. You should replace "none" as displayed in Jira off-the-shelf, with whatever phrase you want to use, using the documentation you've found on the subject
  3. Because you want it on a by-project basis, I think your suggestion of using a separate custom field plugin is the right structure.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events