SageCreateDocument
Description
Section titled “Description”Creates a fiscal document in Sage X3 (Invoice or Credit Note) by inserting records into the three Sage accounting tables: header (YFACTERCAB), line (YFACTERLIN) and analytics (YFACTERAN). Uses a SQL Server connection and executes all inserts within a single atomic transaction.
The node maps the country to the correct Sage configuration (plant, third party, tax regime, accounts) based on the procedures EQZ_MigracionTP_Sage and EQZ_MigracionEcomm_Sage.
Configuration
Section titled “Configuration”| Field | Type | Required | Description |
|---|---|---|---|
| credentials_id | credentials | Yes | Sage SQL Server (MSSQL) credential |
| contato | textarea | No | Contact JSON: {nome, pais, nif}. If empty, uses data.contato from previous node |
| tipificacao | select | No | Document type: FT (Invoice), FR (Invoice-Receipt), NC (Credit Note). Default: FT |
| produtos | textarea | No | Products JSON array. If empty, uses data.produtos from previous node |
| invoice_date | text | No | Date YYYY-MM-DD. If empty, uses current date |
| sage_schema | text | No | Sage database schema (default: LIVE) |
| currency | text | No | ISO currency (default: EUR) |
| canal | text | No | Analytics axis CAN (default: E-COMMERCE) |
| delegacion | text | No | Analytics axis DEL (default: 06) |
| descripcion | text | No | Document description. Supports {{}} variables. Auto-generated if empty |
| sage_user | text | No | CREUSR field value (default: ADMIN) |
| timeout | text | No | Query timeout in milliseconds (default: 30000) |
Credentials
Section titled “Credentials”This module requires a sageCreateDocument type credential (SQL Server) with the following fields:
- host: SQL Server hostname or IP
- user: Database username
- password: Database password
- database: Database name
- port: Port (default: 1433)
- sage_schema: Schema name (default: LIVE)
Country Mapping
Section titled “Country Mapping”| Country | Plant | Type | Third Party | Tax Regime | Account | VAT Code |
|---|---|---|---|---|---|---|
| PT | 22_PT | TPE03 | CT-000028 | PORT | 700050 | PT023 |
| ES | 22_ES | TPE01 | CT-000001 | ESPA | 700000 | ES021 |
Output
Section titled “Output”{ "success": true, "idRegistro": 1234, "schema": "LIVE", "tercero": "CT-000028", "planta": "22_PT", "total": 19.90, "descripcion": "Ventas Ecomm 05/04/2026", "pais": "PT", "tipificacao": "FT", "fecha": "2026-04-05", "message": "Documento Sage creado (ID: 1234) en LIVE.YFACTERCAB"}Usage Example
Section titled “Usage Example”Typical flow: Shopify Webhook → Decision (country) → EditFields (mapping) → SageCreateDocument
{ "credentials_id": "5", "tipificacao": "FT", "invoice_date": "{{created_at}}", "sage_schema": "LIVE", "canal": "E-COMMERCE", "delegacion": "06"}The node automatically reads contato and produtos from the previous node’s output.
- All three inserts (YFACTERCAB, YFACTERLIN, YFACTERAN) run in a single transaction with rollback on failure
- The node calculates the total from the products array (sum of
preco_unitario * quantidade) - Credit Notes (NC) set
INVTYP_0 = 2instead of1 - The analytics axes are: PAI (country), CAN (channel), DEL (delegation), CLI (client)
- If the country is not found in the mapping, it defaults to the Portugal configuration
Related Nodes
Section titled “Related Nodes”- BillptCreateDocument - Create document in Bill.pt
- HubfiscalCreateDocument - Register document in Hub Fiscal
- SqlQueryMSSQL - Execute raw SQL Server queries