Copy this script into ServiceNow under application x_786686_hr_leave (Australia). Table/API names already use the current scope.
Source: src/portal/widgets/hrlx_balance/server.js
/**
* Widget: hrlx_balance — Server Script
* Application: Custom · Scope: x_786686_hr_leave · sys_id: c84db0e8839f0b509f02b0d6feaad3c9
* Shows the current user's remaining leave balance for the current year.
*/
(function () {
data.balances = [];
data.year = new GlideDateTime().getYearLocalTime();
// find employee record of current user
var emp = new GlideRecord('x_786686_hr_leave_employee_v2');
emp.addQuery('u_user', gs.getUserID());
emp.query();
if (!emp.next()) return;
var bal = new GlideRecordSecure('x_786686_hr_leave_bal_v2');
bal.addQuery('u_employee_ref', emp.getUniqueValue());
bal.addQuery('u_year', data.year);
bal.query();
while (bal.next()) {
data.balances.push({
type: bal.getDisplayValue('u_leave_type'),
entitled: parseInt(bal.getValue('u_entitled') || 0, 10),
used: parseInt(bal.getValue('u_used') || 0, 10),
remaining: parseInt(bal.getValue('u_remaining') || 0, 10)
});
}
})();