- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2022 05:54 AM
Hi All,
Am trying to set the option value as FY22 by default in fiscal year using jelly script.
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2022 12:13 PM
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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2022 02:19 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2022 01:40 AM
Have you tried the solution in thread Urgent help need in Jquery script?
It seems to me you have the same problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2022 12:13 PM
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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2022 10:45 AM
Thank you Chris!
It worked!