HR Leave · Australia

Script — BR1_calculate_days.js

ServiceNow Australia · Custom app · Arabic + English readable · scripts copy/paste ready

App typeCustom
Scopex_786686_hr_leave
sys_idc84db0e8839f0b509f02b0d6feaad3c9
Replace{BASE} = your instance
Instance URLs Application Leave requests Business Rules Studio

Copy this script into ServiceNow under application x_786686_hr_leave (Australia). Table/API names already use the current scope.

Source: src/server/business_rules/BR1_calculate_days.js

/**
 * Business Rule: BR1 - Calculate Days + Approver
 * Application: Custom · Scope: x_786686_hr_leave · sys_id: c84db0e8839f0b509f02b0d6feaad3c9
 * Table:  x_786686_hr_leave_req_v2
 * When:   before
 * Insert: true   Update: true
 * Order:  100
 *
 * Calculates u_days_count and resolves the approver before saving.
 */
(function executeRule(current, previous /*null when inserting*/) {

    var util = new x_786686_hr_leave.HRLXProLeaveUtilsV2();

    if (current.u_start_date.changes() || current.u_end_date.changes() || current.isNewRecord()) {
        current.u_days_count = util.calculateBusinessDays(
            current.getValue('u_start_date'),
            current.getValue('u_end_date')
        );
    }

    if (current.u_employee_ref.changes() || current.isNewRecord()) {
        util.setApproverFromEmployee(current);
    }

})(current, previous);