HR Leave · Australia

Script — RP_submit_leave.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 Record Producers Catalog Items

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

Source: src/catalog/RP_submit_leave.js

/**
 * Record Producer Script: Submit Leave Request
 * Application: Custom · Scope: x_786686_hr_leave · sys_id: c84db0e8839f0b509f02b0d6feaad3c9
 * Target table: x_786686_hr_leave_req_v2
 *
 * Maps producer variables to record fields. Runs server-side when submitted.
 * Variables expected: leave_type, start_date, end_date, reason
 */
(function () {

    current.u_requested_for_user = gs.getUserID();
    current.u_leave_type = producer.leave_type;
    current.u_start_date = producer.start_date;
    current.u_end_date = producer.end_date;
    current.u_reason = producer.reason;
    current.u_state = 'submitted';

    // Link to employee profile of the current user (if exists)
    var emp = new GlideRecord('x_786686_hr_leave_employee_v2');
    emp.addQuery('u_user', gs.getUserID());
    emp.query();
    if (emp.next()) {
        current.u_employee_ref = emp.getUniqueValue();
    }

    // BR1 will calculate days and set the approver on insert.

})();