HR Leave · Australia

03 — Service Catalog (Studio From Scratch)

Category HR Leave, Record Producer Submit Leave Request, variables, producer script, publish

Scopex_786686_hr_leave
sys_ide5f5bc9493a303507520703efaba104d
Instance labdev398980
URL token{BASE}
Quick open Visual map Categories Record Producers Employee Center

Visual map — Ch.03 · Service Catalog — intake

See in 10 seconds

Category → Record Producer → variables → publish

You build

Submit Leave Request → req_v2

Track

Development

CATCategory
→
RPProducer
→
VARQuestions
→
SCRIPTMap fields
→
PUBEmployee Center
✓ gs.getUserID()✓ Whitelist leave_type✓ Catalog UI Policy ≠ UI Policy✗ Trust variable identity✗ Skip employee lookup

Full visual path (all chapters): VISUAL_FROM_SCRATCH_00_16.html

Studio-only from scratch: Service Catalog intake for leave requests. Requires req_v2 table and employee role from chapters 01–02.

Also open: Properties + Direct Links · Schema · Studio Create All Objects · Previous: 02 Administration

How catalog objects relate

Part 1 Category (HR Leave)
        │
        ▼
Part 2 Record Producer → Part 3 Variables
        │
        ▼
Part 4 Producer script (maps variables → req_v2)
        │
        ▼
Part 5 Publish → Employee Center / Portal catalog
        │
        ▼
BR1 days + approver → BR2 event → Flow approval

Flow: employee1 opens catalog → submits → req_v2 inserted in submitted state → same lifecycle as UI Action Submit.


Rule 0 — Before any object (Application + Update Set + Studio)

Repeat these checks before creating or editing any application file. This section is also section 00 Update Set — create the capture set first.

  1. Application picker — top-right globe / application menu → select HR Leave (x_786686_hr_leave). Never leave Global selected when creating scoped artifacts.
  2. Update Set — All → System Update Sets → Local Update Sets → New:
    FieldValue
    NameHR Leave – Build
    ApplicationHR Leave
    StateIn Progress
    DescriptionCaptures all HR Leave lab artifacts
    After submit: open the record → click Make Current. Direct list: {BASE}/sys_update_set_list.do
  3. Open Studio — {BASE}/$studio.do → confirm header shows HR Leave.

If artifacts land in Global scope, delete them and recreate under HR Leave. ACLs and events created globally will not behave correctly for this app.

Verify Update Set: Create a test Script Include in Studio → open HR Leave – Build → Related List Customer Updates shows the new file.


Part 1: Catalog Category — HR Leave

Purpose

Groups the Submit Leave Request record producer under a dedicated HR Leave catalog category.

Navigation path

Direct URL

Prerequisites

Form fields

FieldValue
TitleHR Leave
DescriptionLeave requests and balances
Activetrue
Order100
ApplicationHR Leave

Step-by-step create

  1. Service Catalog → Categories → New.
  2. Fill Title, Description, Order from table. Active = true.
  3. Submit. Note category sys_id for record producer.

Verify checklist

Demo / test

Open Employee Center → catalog browse → HR Leave category visible (after producer published).


Part 2: Record Producer — Submit Leave Request

Purpose

Service Catalog item that inserts submitted req_v2 from catalog variables.

Navigation path

Direct URL

Prerequisites

Form fields

FieldValue
NameSubmit Leave Request
Tablex_786686_hr_leave_req_v2
CategoryHR Leave
Rolesx_786686_hr_leave.employee
Activetrue
ApplicationHR Leave

Step-by-step create

  1. Record Producers → New. Fill header fields from table.
  2. Category = HR Leave. Table = req_v2. Roles = employee.
  3. Save. Continue to Part 3 for variables and Part 4 for script.

Verify checklist

Demo / test

Open producer form → Table field shows x_786686_hr_leave_req_v2.


Part 3: Catalog Variables

Purpose

Four question variables mapped by the producer script to req_v2 u_* fields.

Navigation path

Direct URL

Prerequisites

Form fields — each variable New

NameLabelTypeQuestionMandatory
leave_typeLeave TypeChoiceLeave TypeYes
start_dateStart DateDateStart DateYes
end_dateEnd DateDateEnd DateYes
reasonReasonMulti Line TextReasonNo

Choice values for leave_type: annual, sick, personal (match req_v2 u_leave_type choices).

Step-by-step create

  1. Open Submit Leave Request producer → Variables related list → New.
  2. For each row: Name must match producer.* references in script. Set Label, Type, Mandatory.
  3. Order: leave_type, start_date, end_date, reason.

Verify checklist

Demo / test

Try It → variable form renders all four questions.


Part 4: Producer Script

Purpose

Server-side script maps catalog variables to req_v2 fields and sets state submitted. Source: src/catalog/RP_submit_leave.js.

Navigation path

Direct URL

Prerequisites

Step-by-step create

  1. Open producer → Script tab.
  2. Paste full script below.
  3. Save.

Full script (paste-ready)

/**
 * Record Producer Script: Submit Leave Request
 * Application: Custom · Scope: x_786686_hr_leave · sys_id: 83d5298c932b8f107520703efaba1072
 * 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.

})();

Verify checklist

Demo / test

Background: no errors on save. Catalog submit tested in Part 5.


Part 5: Publish and Test

Purpose

Publish catalog item and verify end-to-end submit from Employee Center.

Navigation path

Direct URL

Prerequisites

Step-by-step create

  1. Record Producer → Related Lists → Catalogs → add to HR Leave category.
  2. Service Catalog → open producer → Publish.
  3. Login as employee1 → Employee Center → HR Leave → Submit Leave Request.
  4. Fill variables → Submit.
  5. Verify req_v2 created in submitted state; u_days_count and u_approver_user set by BR1.
  6. Verify Flow starts for manager1 approval.

Verify checklist

Demo / test

employee1 submits → req_v2 row, BR1 sets days + approver, Flow starts.

Service Catalog verify checklist

Complete after Parts 1–5.

  1. HR Leave category active.
  2. Record Producer scoped to HR Leave with four variables.
  3. Producer script from src/catalog/RP_submit_leave.js pasted.
  4. Published and visible in Employee Center.
  5. E2E submit creates submitted req_v2.