Want to set current year value in "Fiscal Year"

augustinchacko
Kilo Contributor

Hi All,

Set Default Year for Create Demand Budget of a DMND Year.
Under Related Links, when we click on "Create Demand Budget".
On the Popup set default Year "Current Year" for field Fiscal Year. (Means In 2020 will be 2020 in 2021 will be 2021 etc..)

Thanks

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@augustinchacko 

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:

find_real_file.png

find_real_file.png

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ankur,

Would there be any impact on other parameters by modifying this UI macros ?

@augustinchacko 

As already informed please find the below responses to your question

1) it is not recommended to change the UI Macro code as the values for the Fiscal Year come from the fiscal_period table based on the query and this is OOB code

2) If you still require that you can modify the Macro as suggested above

The script gets the current year i.e. 2020 and then sets that in drop down

Note: Since you are updating this OOB macro it might pose an issue when upgrade happens

If you find my response solved your issue, please mark answer as Correct & 👍Helpful to help others with the same response find the answer more quickly

Regards
Ankur

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

@augustinchacko 

Glad to hear that it helped.

If you find my response solved your issue, please mark answer as Correct & 👍Helpful to help others with the same response find the answer more quickly.

Regards
Ankur

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