Outbound REST Message — Complete Setup (Dev + Admin)
Matches Studio screenshot: HR Leave → Outbound Integrations → REST Messages → HRLX ERP Push Decision
Fixes common issues: Default GET only, empty headers, endpoint not set, 401 on test.الأسلوب: عربية + إنجليزية تكمّلان بعضهما — بدون ترجمة حرفية لأسماء الشاشات.
Inbound test tool: REST API Explorer ($restapi.do)
Outbound test tool: REST Message → HTTP Method → Send (not Explorer)
Related: 12_INTEGRATION_FULL_GUIDE.md §5 · outbound_rest_message.js · HRLXProIntegrationUtilsV2.js
Phase 0 — Prerequisites (before REST Message form)
0.1 Application scope
Create everything inside HR Leave — same as inbound. — اختر HR Leave من App picker أو Studio قبل New.
0.2 System property — ERP endpoint (mandatory)
Navigate:
All > System Properties → New (scope HR Leave) — Open direct
| Field | Value |
|---|---|
| Name | x_786686_hr_leave.config.erp_endpoint |
| Type | string |
| Value (lab) | https://webhook.site/your-unique-id or mock ERP URL |
| Value (prod) | Real ERP REST URL |
| Application | HR Leave |
في حقل Endpoint على REST Message تضع اسم الخاصية (كما في صورتك) — ليس URL ثابتًا في الكود.
Verify:
gs.info(gs.getProperty('x_786686_hr_leave.config.erp_endpoint'));
0.3 Sample leave record for test
One record in x_786686_hr_leave_req_v2 with:
- u_state = approved or rejected
- u_number populated
- u_employee_ref linked to employee with u_employee_id = EMP001
Phase 1 — Create REST Message (container) — every field
Option A — Studio (matches your screenshot)
- URL: /now/studio
- Open app HR Leave
- Left tree: Outbound Integrations → REST Messages → Create (or +)
Option B — Classic UI
Navigate:
All > System Web Services > Outbound > REST Message → New — Open direct
REST Message form — fill exactly
| Field | Required | Value | Notes |
|---|---|---|---|
| Name | Yes | HRLX ERP Push Decision | Unique; used in RESTMessageV2(‘Name’, ‘Method’) |
| Application | Yes | HR Leave | NOT Global |
| Accessible from | Yes | This application scope only | Professional default |
| Description | No | Push leave approval/rejection to ERP/Payroll | Handover doc |
| Endpoint | Yes | x_786686_hr_leave.config.erp_endpoint | Property name (see screenshot) |
Screenshot check:
| Your screen | Correct? |
|---|---|
| Name = HRLX ERP Push Decision | ✓ |
| Application = HR Leave | ✓ |
| Accessible from = scope only | ✓ |
| Endpoint = property name | ✓ |
Submit / Save the REST Message record. — هذا السجل = حاوية فقط. الـ POST والـ Body في HTTP Methods (الخطوة التالية).
Phase 2 — HTTP Request tab (message-level headers)
Open REST Message → tab HTTP Request
HTTP Headers (related list on message)
Click Insert a new row:
| Name | Value |
|---|---|
| Content-Type | application/json |
| Accept | application/json (optional) |
Option A: Headers here (apply to all methods)
Option B: Headers on HTTP Method only (POST method) — either works
Submit.
Phase 3 — HTTP Method POST (fix “Default GET”)
New REST Messages often create Default GET automatically. You need POST for ERP push. — في صورتك يظهر Default GET — أنشئ POST جديد (يمكنك حذف GET أو تجاهله).
Related list: HTTP Methods → New
HTTP Method — every field
| Field | Required | Value |
|---|---|---|
| Name | Yes | Push Decision |
| HTTP method | Yes | POST |
| Endpoint override | No | (empty) |
| HTTP method URL | No | (empty) |
| Active | Yes | true |
| Authentication type | Lab | Basic or Inherit from parent |
Submit.
Tab: HTTP Request (on method)
Add header if not on parent:
| Name | Value |
|---|---|
| Content-Type | application/json |
Tab: HTTP Query Parameters (optional)
Leave empty unless ERP needs query string.
Tab: Variables (for non-table fields)
employee_id is on employee table, not leave req — define a variable:
Related list Variables → New:
| Field | Value |
|---|---|
| Name | employee_id |
| Value | (empty — set at runtime or test) |
Used in body as ${employee_id}.
Tab: Content (HTTP Body) — body template
Paste:
{
"leave_number": "${u_number}",
"employee_id": "${employee_id}",
"state": "${u_state}",
"start_date": "${u_start_date}",
"end_date": "${u_end_date}",
"decision_time": "${sys_updated_on}"
}
Field mapping note:
| Token | Source |
|---|---|
| ${u_number} | Field on x_786686_hr_leave_req_v2 |
| ${u_state} | Same |
| ${u_start_date} / ${u_end_date} | Same |
| ${sys_updated_on} | Same |
| ${employee_id} | Variable — set in Test or script from u_employee_ref.u_employee_id |
Option B — script-only payload (no template variables):
Use HRLXProIntegrationUtilsV2.outboundPushDecision() — builds JSON in script.
Save HTTP Method.
Phase 4 — Connection & Credential Alias (auth)
Navigate:
All > System Web Services > Connection & Credential Aliases — Open direct
Option A — Lab (Basic)
| Step | Action |
|---|---|
| 1 | New Connection alias: x_786686_hr_leave_erp |
| 2 | Type: HTTP(s) |
| 3 | New Credential (Basic auth): ERP username/password |
| 4 | Link credential to connection alias |
| 5 | On REST Message or HTTP Method → Authentication → select alias |
Option B — Production (OAuth 2.0)
| Step | Action |
|---|---|
| 1 | OAuth profile for ERP token URL |
| 2 | OAuth credential on alias |
| 3 | Attach to REST Message HTTP Method |
لا تضع كلمة المرور في System Property — فقط في Credential.
Phase 5 — Test outbound (REST Message “Send” = outbound Explorer)
This is the outbound equivalent of REST API Explorer Send. — اختبار الصادر = من HTTP Method وليس من $restapi.do.
Steps
- Open REST Message HRLX ERP Push Decision
- Related list HTTP Methods → open Push Decision (POST)
- Click Send / Test / Preview (label varies by release)
- When prompted for test values:
- Record: pick a leave request sys_id (approved/rejected)
- Variable employee_id: enter EMP001 (or value from linked employee) - Review Response panel:
- 200 / 201 / 204 = success
- 401 / 403 = fix Connection & Credential Alias
- 404 = wrong endpoint property URL
- 400 = ERP rejected JSON — fix body template - If using webhook.site — open webhook URL and confirm JSON received
Troubleshooting
| Symptom | Fix |
|---|---|
| Only Default GET exists | Create POST method §3 |
| Test sends GET | Open POST method, not GET |
| Empty endpoint | Set property erp_endpoint |
| 401 Unauthorized | Credential alias + auth on method |
| Variables empty in body | Set employee_id in Variables or Test form |
| Works in Test, fails in Flow | Flow runs as different user — use system/alias |
Phase 6 — Call from Flow (after test OK)
Navigate:
All > Flow Designer → Flow on x_786686_hr_leave_req_v2 — Open direct
| Setting | Value |
|---|---|
| Trigger | Record Updated |
| Condition | u_state changes to approved OR rejected |
| Action | Run Script or IntegrationHub HTTP (if available) |
Run Script example:
new x_786686_hr_leave.HRLXProIntegrationUtilsV2().outboundPushDecision(current.sys_id);
RESTMessageV2 by name (uses your REST Message config):
var gr = current; // leave record
var empId = '';
if (gr.u_employee_ref) {
var e = gr.u_employee_ref.getRefRecord();
empId = e.getValue('u_employee_id');
}
var rm = new sn_ws.RESTMessageV2('HRLX ERP Push Decision', 'Push Decision');
rm.setStringParameter('employee_id', empId);
// optional: rm.setEccParameter('skip_sensor', 'true');
var resp = rm.execute();
Publish Flow.
Option B — Async Business Rule: see outbound_rest_message.js comment block.
Phase 7 — Outbound contract document (handover)
Save for HRIS/ERP team:
| Item | Value |
|---|---|
| Direction | ServiceNow → ERP |
| Method | POST |
| URL | Value of x_786686_hr_leave.config.erp_endpoint |
| Content-Type | application/json |
| Auth | Basic (lab) / OAuth (prod) — alias x_786686_hr_leave_erp |
| Body sample | See §3 Content tab |
Why not REST API Explorer for outbound?
Explorer calls into ServiceNow. Outbound calls external URL — use REST Message Test or Postman against ERP directly.
Studio tree (your screenshot)
HR Leave (Studio)
├─ System Properties
│ └─ x_786686_hr_leave.config.erp_endpoint
├─ Inbound Integrations
│ └─ Scripted REST APIs → HRLX Leave API → Create Leave (POST)
└─ Outbound Integrations
└─ REST Messages → HRLX ERP Push Decision
├─ HTTP Request (headers)
└─ HTTP Methods → Push Decision (POST) → Content (JSON)
Checklist — professional practice
- [ ] Property x_786686_hr_leave.config.erp_endpoint set (lab URL works)
- [ ] REST Message in HR Leave scope, accessible scope only
- [ ] Endpoint field = property name (not hardcoded URL in record)
- [ ] POST method Push Decision exists (not only Default GET)
- [ ] Content-Type: application/json header
- [ ] Body template saved on POST method
- [ ] Variable employee_id defined OR script sets it
- [ ] Connection alias x_786686_hr_leave_erp + credential
- [ ] Send/Test returns 2xx on sample leave record
- [ ] Flow or BR calls push on approved/rejected
- [ ] Contract documented for ERP team
Related files
| File | Purpose |
|---|---|
| outbound_rest_message.js | Script patterns + async BR sample |
| HRLXProIntegrationUtilsV2.js | outboundPushDecision() |
| system_properties.md | Property definitions |
| SCRIPTED_REST_INBOUND_SETUP.md | Inbound counterpart |
| rest_api_explorer.md | Inbound Explorer only |