cardinal

Form and list options

Buttons, list colours, connections, calendar and Gantt views, indexes and search, all from YAML.

These keys change how the desk shows a RecType. None needs frontend code.

Form buttons

actions adds buttons to the form. A Server Action calls an RPC. A Route opens a desk path, whose {fieldname} parts the desk fills from the record.

erp/rectypes/asset.yaml
actions:
  - {label: Scrap Asset, action_type: Server Action, action: erp.asset.scrap,
     depends_on: "doc.docstatus == 1 && doc.status != 'Scrapped'"}
  - {label: Restore Asset, action_type: Server Action, action: erp.asset.restore,
     depends_on: "doc.docstatus == 1 && doc.status == 'Scrapped'"}
KeyMeaning
labelThe button text
action_typeServer Action or Route
actionThe RPC path, or the desk path
groupA toolbar dropdown that holds it, such as Create. Without it the button stands alone
depends_onAn expression over doc. Without it the button shows on saved records only
hiddenHides it

The RPC receives rectype and doc:

erp/lib/rpc/budget.ex
@rpc requires: {:cancel, "Budget"}, args: [rectype: :string, doc: :map]
def revise(ctx, %{doc: %{"name" => name}}) do
  with {:ok, new, fx} <- Budget.revise(ctx, name), do: {:ok, %{"name" => new}, fx}
end

List colours

states maps a status to an indicator colour in the list.

states:
  - {title: Draft, color: danger}
  - {title: Submitted, color: info}
  - {title: Fully Depreciated, color: success}

For logic beyond a status match, use a list plugin's indicator. See Desk plugins.

Connections

links lists records of other RecTypes that point at this one. The form shows them in its Connections panel.

crm/rectypes/lead_sync_source.yaml
links:
  - {link_rectype: Failed Lead Sync Log, link_fieldname: source}

Each entry takes link_rectype, link_fieldname, an optional group and hidden. To add groups to another app's RecType, use the manifest's connections:

crm/app.exs
connections: [
  {"CRM Organization", [%{label: "Deals", items: [{"CRM Deal", "organization"}]}]}
]

An item is {rectype, field}, or {rectype, "<table>.<field>"} for a child row. Apps that list the same RecType add up.

Calendar and Gantt

erp/rectypes/task.yaml
calendar: {start: exp_start_date, end: exp_end_date, title: subject}
gantt: {start: exp_start_date, end: exp_end_date, title: subject, progress: progress, dependencies: depends_on}

calendar takes start and optional end, title and all_day. gantt takes start, end and optional title, progress and dependencies, a Table whose rows name the records this one depends on.

Indexes

eden/rectypes/eden_link.yaml
indexes:
  - {fields: [src_rectype, src_name]}
  - {fields: [dst_rectype, dst_name]}

Add unique: true for a unique index.

Mark fields with in_global_search: true. Then list the RecType in the manifest, in the order Ctrl+G shows the groups:

crm/app.exs
global_search: ["CRM Lead", "CRM Deal", "Contact", "CRM Organization", "FCRM Note"]

The installer adds the list to Global Search Settings. Hits are only records the user may read.

Create menu

The manifest's create puts entries in a saved record's Create menu. Each is %{from, to, rpc} with an optional depends_on. The RPC answers an unsaved to record for source_name, usually through Cardinal.Mapper. See Platform modules.

On this page