Skip to content
Light
English

Order Fields Policy

This article explains Demander’s Order Fields Policy.

The Order Fields Policy allows controlling the behavior of order fields according to the commercial context (for example: salesperson, customer, order type, etc.).

For each supported field, you can define:

  • Visibility (show/hide).
  • Requirement (require filling).
  • Locking (display without allowing changes).
  • Options filter (allow/block values).
  • Automatic value selection (when applicable).

The objective is to address scenarios where the company needs to limit the use and/or options of order fields by context (for example: one context may see a filtered list, another may require filling, another may hide the field).

The solution was designed extensibly: new fields can be added while keeping the same jsonRegras contract and without database schema changes. To check which fields are currently available, see Supported fields and examples.

Policy configuration involves identification fields, context filters, and the rules JSON. This section is based on fields specified in the integration table 280 - PoliticaCamposPedido.

  • codigo: identifies the policy in the customer context.
  • descricao: policy description.
  • ativo: defines whether the policy can be applied (0 = inactive, 1 = active).
  • prioridade: tie-breaker criterion between applicable policies (lower value indicates higher priority).

The filters below are optional. When filled, they restrict policy usage to the corresponding context (and increase specificity).

  • codVendedor: filter by salesperson.
  • codCliente: filter by customer.
  • codListaPreco: filter by price list.
  • codTipoPedido: filter by order type.
  • codFormaPagamento: filter by payment method.
  • codCondicaoPagamento: filter by payment condition.
  • codTipoFrete: filter by freight type.
  • codTipoDesconto: filter by discount type.
  • codSegmento: filter by segment.
  • codFilial: filter by branch.
  • codTransportadora: filter by carrier.
  • codRedespacho: filter by redispatch.
  • codDivisaoVendas: filter by sales division.

Filter Examples

Example 1: policy applicable only when codVendedor, codCliente, and codDivisaoVendas match.

  • prioridade = 1
  • codVendedor = 45
  • codCliente = 1001
  • codDivisaoVendas = DV01

In this case, the policy only applies when the order is in the context of salesperson 45, customer 1001, and division DV01 simultaneously. If any value differs, the policy does not apply.

Example 2: policy applicable when codVendedor and codDivisaoVendas match, regardless of customer.

  • prioridade = 5
  • codVendedor = 45
  • codDivisaoVendas = DV01

In this case, the policy applies to any customer, as long as the order is in the context of salesperson 45 and division DV01.

When both policies (Example 1 and Example 2) are applicable, the system prefers the more specific one (Example 1) because its priority is lower (1), indicating it should be applied first.

  • jsonRegras: JSON containing dynamic order field rules. The contract is described in JSON Rules Contract.

The jsonRegras field stores a JSON defining field behaviors:

{ "campos": { "nomeCampo": { "obrigatoriedade": ("VISIVEL","OBRIGATORIO","BLOQUEADO","OCULTO"), -> field behavior in order data "filtro": { "tipo": ("PERMITIR","BLOQUEAR") "valores": ["1", "2", "3"] -> Values available/blocked according to "tipo" }, "selecionado": "2" -> Value automatically selected or send null to not select automatically. } } }

Behavior

  • VISIVEL: keeps the field available for use.
  • OBRIGATORIO: requires filling the field.
  • BLOQUEADO: does not allow editing the field.
  • OCULTO: hides the field.
  • PERMITIR: displays only the options listed in valores for selection.
  • BLOQUEAR: hides the options listed in valores from selection.
  • selecionado: value automatically selected when the rule is applied.

This section focuses on fields supported in the application and usage examples. When adding new fields, documentation maintenance is generally restricted to this section.

Field: Sales Division (divisaoVendas)

  • Allows controlling visibility, requirement, locking, options filtering, and automatic value selection.

Example of jsonRegras for divisaoVendas:

{
"campos": {
"divisaoVendas": {
"obrigatoriedade": "VISIVEL",
"filtro": {
"tipo": "PERMITIR",
"valores": ["1", "2", "3"]
},
"selecionado": "2"
}
}
}

How the System Selects the Policy (Priority and Specificity)

Section titled “How the System Selects the Policy (Priority and Specificity)”

When multiple policies are applicable, the rule best matching the context prevails. Expected selection logic:

  • Consider only active policies.
  • A policy is applicable when all filled filters match the order scenario values.
  • Unfilled filter fields are considered indifferent (more generic policy).
  • Recommended tie-breaking sort order: priority ASC (lower value indicates higher priority), then specificity (higher number of applied filters), then id DESC.
  • Return/apply only the best policy (first after sorting).
  • Scenario 1: Visible field with allowed list (only 1, 2, and 3).
    • When the policy applies to the order context, the user will only see these options in the field.
  • Scenario 2: Automatic selection.
    • If selecionado is present in the final list after filtering, the system automatically fills the field with that code.
  • Scenario 3: Hidden field for a specific context.
    • When the policy defines OCULTO, the field is no longer displayed and the current value is removed from the order.
    1. Access Order Fields Policy.
    1. Fill in Code, Description, Company (idClienteRetta), Active, and Priority.
    1. Configure context filters (salesperson, customer, order type, etc.). The more filters filled, the more specific the policy.
    1. In Rules JSON, enter jsonRegras following the official contract.
  • For details on each field meaning, see Configuration Fields.
    1. Save the policy and sync data so applications and integrations receive the configuration.