- 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-17-2022 06:26 AM
Did you try this one
<j:set var = "jvar_name" value="FY22"/>
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2022 07:20 AM
Thank you Vasanth!
I have tried your code, but it did not worked out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2022 06:38 AM
I have shared solution for similar thing 2 years ago and shared UI macro updated script
Want to set current year value in "Fiscal Year"
sharing script here as well
that Fiscal Year comes from OOB ui page "entity_funding" and within that from the UI Macro "ppm_fiscal_year"
The UI Macro fetches the value from this table "fiscal_period" based on the query
There should be an entry in that table for that year then it would show
UI Page URL: https://<instanceName>.service-now.com/nav_to.do?uri=sys_ui_page.do?sys_id=d46e0e2493201200ea933007f67ffb22
UI Macro URL: https://<instanceName>.service-now.com/nav_to.do?uri=sys_ui_macro.do?sys_id=a724cae093201200ea933007f67ffbe7
I would recommend not changing the UI Macro as this is OOB. If you still require the drop down to show current year as default then update UI Macro as below
Updated UI Macro Script: highlighted in bold
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_gr" object="true">
var fiscalPeriods = new GlideRecord('fiscal_period');
fiscalPeriods.addQuery('fiscal_type','year');
fiscalPeriods.orderBy('fiscal_start_date_time');
fiscalPeriods.query();
fiscalPeriods;
</g:evaluate>
<g:evaluate jelly="true" object="true" var="jvar_currentYear">
var gdt = new GlideDateTime();
var year = gdt.getYearUTC();
year;
</g:evaluate>
<div id="#year-field">
<div class="form-group is-filled" id="fund">
<div nowrap="true" type="string" choice="0" data-type="label">
<label class="col-sm-12 col-md-4 control-label">
<span class="required-marker label_description"></span>
<span class="label-text">${gs.getMessage('Fiscal Year')}</span>
</label>
</div>
<div class="col-sm-12 col-md-6 form-field input_controls">
<select class="form-control" name="fiscal_year" id="fiscal_year">
<j:while test="${jvar_gr.next()}">
<option value="${jvar_gr.getValue('sys_id')}">${jvar_gr.getValue('name')}</option>
</j:while>
<option value="${jvar_currentYear}" selected="selected">${jvar_currentYear}</option>
</select>
</div>
<div class="col-sm-12 col-md-2 form-field-addons"></div>
</div>
</div>
</j:jelly>
Screenshots:
Now for this year it would be 2022
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-17-2022 07:02 AM
Thank you Ankur for the explanation!
I have tried your code and i could see current year but other options not able to select such as FY19, FY20 and so on..
Requirement is: current year should come by default and at the same i should able to select the other options as well.