Bỏ qua, đến nội dung

Cài đặt và sử dụng

Cài đặt

Plugin @digiforce-nc/plugin-action-custom-request cần cả clientserver. Kích hoạt qua trang Plugin Manager.

Sau khi cài, plugin tạo hai bảng trong database: customRequestscustomRequestsRoles.

Tạo cấu hình Custom Request

Bước 1: Mở quản lý Custom Requests

Vào SettingsCustom Requests (hoặc qua API trực tiếp). Đây là nơi admin tạo và quản lý các request template.

Bước 2: Tạo request mới

Điền thông tin cấu hình:

TrườngMô tả
KeyKhóa định danh duy nhất (VD: sync-to-crm)
URLĐịa chỉ đích — hỗ trợ template variables
MethodGET, POST, PUT, PATCH, DELETE
HeadersHTTP headers — hỗ trợ template variables
BodyRequest body (JSON) — hỗ trợ template variables
ParamsQuery parameters

Bước 3: Gán roles

Chọn role nào được phép sử dụng request này. Chỉ user thuộc role đã gán mới thấy và kích hoạt được action.

Thêm nút action

  1. Mở Schema Editor trên block Table hoặc Form.
  2. Vào Configure actions → chọn Custom request.
  3. Chọn request đã tạo từ danh sách (lọc theo role hiện tại).
  4. Lưu schema.

Sử dụng

  1. User nhấn nút action đã cấu hình.
  2. Server đọc cấu hình request từ DB.
  3. Server resolve template variables (currentRecord, currentUser, $nForm) bằng dữ liệu thực.
  4. Server gửi HTTP request đến URL đích qua axios.
  5. Kết quả trả về hiển thị cho user.

Template variables

Trong các trường URL, headers, body, admin sử dụng cú pháp template để chèn dữ liệu động:

BiếnMô tảVí dụ
currentRecord.*Dữ liệu bản ghi hiện tạicurrentRecord.id, currentRecord.email
currentUser.*Thông tin user đang thao táccurrentUser.id, currentUser.email
$nForm.*Dữ liệu từ form hiện tại (nếu action trên form)$nForm.amount

Lưu ý

Sử dụng backtick hoặc cú pháp template của hệ thống. Không dùng cú pháp double curly brace — tham chiếu biến bằng tên trực tiếp trong giao diện cấu hình.

Ví dụ thực tế

Webhook khi duyệt đơn: URL = https://hook.example.com/approve, Method = POST, Body chứa currentRecord.idcurrentRecord.status. Gán cho role "Approver".