Skip to content

SageCreateDocument

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.

FieldTypeRequiredDescription
credentials_idcredentialsYesSage SQL Server (MSSQL) credential
contatotextareaNoContact JSON: {nome, pais, nif}. If empty, uses data.contato from previous node
tipificacaoselectNoDocument type: FT (Invoice), FR (Invoice-Receipt), NC (Credit Note). Default: FT
produtostextareaNoProducts JSON array. If empty, uses data.produtos from previous node
invoice_datetextNoDate YYYY-MM-DD. If empty, uses current date
sage_schematextNoSage database schema (default: LIVE)
currencytextNoISO currency (default: EUR)
canaltextNoAnalytics axis CAN (default: E-COMMERCE)
delegaciontextNoAnalytics axis DEL (default: 06)
descripciontextNoDocument description. Supports {{}} variables. Auto-generated if empty
sage_usertextNoCREUSR field value (default: ADMIN)
timeouttextNoQuery timeout in milliseconds (default: 30000)

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)
CountryPlantTypeThird PartyTax RegimeAccountVAT Code
PT22_PTTPE03CT-000028PORT700050PT023
ES22_ESTPE01CT-000001ESPA700000ES021
{
"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"
}

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 = 2 instead of 1
  • 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