How to get the display values of a choice list field in Jelly

nathanfirth
Tera Guru

So I am rendering a choice list field in a UI macro. I am able to get the element and O can call .getChoices() which returns the internal values of the choices. But what about the display values for the choices? Any ideas?

 

  <g:evaluate jelly="true">

      var element = gr.getElement(jelly.jvar_field);

      var elemDesc = element.getED();

  </g:evaluate>

 

<j:if test="${elemDesc.isChoiceTable()}">

  <select>

  <j:forEach items="${j2js(element.getChoices())}" var="jvar_choice">

      <option value="${jvar_choice}">${jvar_choice}</option>

  </j:forEach>

  </select>

</j:if>

 

I've tried using getChoiceValue() and getDisplayValue but both return null

4 REPLIES 4

wshekyls
Tera Contributor

Hi Nathan,



Did you ever solve this issue?


Warren,



I did. I dont think it's documented anywhere and I forget how I found it, but I believe you have to ditch the "getChoices()" method and use the following instead:



                          <select name="" class="form_field">


                              <j:forEach items="${GlideScriptChoiceList.getChoiceList(gr.getTableName(), element.getName())}" var="jvar_choice">


                                  <option value="${jvar_choice.value}">


                                      ${jvar_choice.label}


                                  </option>


                              </j:forEach>


                          </select>


WOW, this is a lifesaver. I saved 20+ hours of my life.


nm13
Kilo Guru

Requesting your attention to this post Nathan. Kindly take a look:

https://community.servicenow.com/community?id=community_question&sys_id=486d5571db246f802be0a851ca961952