UI Page - Jelly Script

J P Rohini
Tera Contributor

Hi All,

Am trying to set the option value as FY22 by default in fiscal year using jelly script.

find_real_file.png

I have used set tag, but it did not worked out:

Jelly script in UI page:

<j:while test "${jvar_gr.next()}">

<option value ="${jvar_gr.getValue('sys_id')}">${jvar_gr.getValue('name')}</option>

<j1: set var = "jvar_name" value="FY22"/>

</j:while>

Can anyone suggest me, how we can achieve this..

Any help is appreciated!

Thanks in advance!

1 ACCEPTED SOLUTION

ChrisBurks
Giga Sage

Reading your post for me it seems like you're trying to have the HTML select element be set to "FY22" on first render. Is that correct?

If so then within the "j:while" loop is there a reason not to use a "j:if" statement along with using the "selected" attribute on the option element?

Note: The "selected" attribute on an option element can be used to create a default value for a select element.

Here's an example that should work based on your post:

<select>
<j:while test "${jvar_gr.next()}">
 <!-- check if the next item is the same as FY22 and set the selected attr if true -->
 <j:if test="${jvar_gr.getValue('name') == 'FY22'}">
   <option value ="${jvar_gr.getValue('sys_id')}"  selected="true" >${jvar_gr.getValue('name')}</option>
  </j:if>
  <!-- check if the next item is not the same as FY22, then only set option  -->
  <j:if test="${jvar_gr.getValue('name') != 'FY22'}">
   <option value ="${jvar_gr.getValue('sys_id')}">${jvar_gr.getValue('name')}</option>
  </j:if>
</j:while>
</select>

View solution in original post

8 REPLIES 8

@J P Rohini 

my solution will still show other options and just add current year as new option and will be default one

try to debug further

I have already shared part of solution

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Have you tried the solution in thread Urgent help need in Jquery script?

It seems to me you have the same problem.

 

ChrisBurks
Giga Sage

Reading your post for me it seems like you're trying to have the HTML select element be set to "FY22" on first render. Is that correct?

If so then within the "j:while" loop is there a reason not to use a "j:if" statement along with using the "selected" attribute on the option element?

Note: The "selected" attribute on an option element can be used to create a default value for a select element.

Here's an example that should work based on your post:

<select>
<j:while test "${jvar_gr.next()}">
 <!-- check if the next item is the same as FY22 and set the selected attr if true -->
 <j:if test="${jvar_gr.getValue('name') == 'FY22'}">
   <option value ="${jvar_gr.getValue('sys_id')}"  selected="true" >${jvar_gr.getValue('name')}</option>
  </j:if>
  <!-- check if the next item is not the same as FY22, then only set option  -->
  <j:if test="${jvar_gr.getValue('name') != 'FY22'}">
   <option value ="${jvar_gr.getValue('sys_id')}">${jvar_gr.getValue('name')}</option>
  </j:if>
</j:while>
</select>

Thank you Chris!

It worked!