> ## Documentation Index
> Fetch the complete documentation index at: https://docs.farmtrace.co.za/llms.txt
> Use this file to discover all available pages before exploring further.

# Function setup

> Define Dsync workflows with a function record and nested form configuration.

A function is a configurable Dsync workflow. Its setup record gives the workflow a name, category, display order, and one or more nested forms. Forms can collect values, resolve local reference data, handle scans, and post records to the configured destination.

This reference lists only the keys consumed by the current function setup path. Local database fields and runtime state are not part of the setup contract.

## Setup record

The function sync consumes these setup columns:

| Setup column    | Required | Use                                                                                    |
| --------------- | -------- | -------------------------------------------------------------------------------------- |
| `Function Name` | Yes      | The name shown in the Dsync function list and passed through the workflow.             |
| `Function JSON` | Yes      | A JSON object containing the function category, root form, and optional display order. |

Enter the JSON object as JSON text in `Function JSON`. Do not wrap it in a second JSON string and do not add comments or trailing commas.

<Note>
  Put the category in the lowercase `category` property inside `Function JSON`. A separate `Category` setup column is not used by the function sync path.
</Note>

## Function JSON

The top-level object has these keys:

| Key        | Type    | Required | Default | Use                                                                                                         |
| ---------- | ------- | :------: | ------- | ----------------------------------------------------------------------------------------------------------- |
| `category` | string  |    Yes   | —       | Groups the function in the Dsync function list.                                                             |
| `form`     | object  |    Yes   | —       | Defines the root form. See [Form fields](/dsync/function-setup/form-fields).                                |
| `order`    | integer |    No    | `9999`  | Controls ascending display order. Functions without an order are placed after explicitly ordered functions. |

Do not add a top-level `function` key to identify the workflow. The displayed name comes from the setup column `Function Name`.

## Minimal example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "category": "Operations",
  "order": 10,
  "form": {
    "formType": "single",
    "postTo": "Field records",
    "components": [
      {
        "compType": "textinput",
        "dispMessage": "Notes",
        "postTargetCol": "Notes",
        "required": true
      }
    ]
  }
}
```

The `components` array contains one object per field or action. Use the [component type reference](/dsync/function-setup/component-types) to choose a renderer and the [component field reference](/dsync/function-setup/component-fields) to configure it.

## Nested forms

A form can contain another form in its `form` key. The child object uses the same form keys as the root, so nested forms can contain their own components, destination, UI options, formulas, and further child forms.

Use `headerPostID` and the form's `postTo` value when a child record must be linked to a parent record. Test the parent and child submission together because the exact destination and relation columns belong to your account configuration.

## Before publishing

* Check that `Function Name` and `Function JSON` are present in the setup record.
* Validate the complete `Function JSON` object, including every nested `form` and `components` value.
* Keep `category` and `form` at the top level. A malformed row is skipped during function synchronization.
* Give every component that should submit a value a valid `postTargetCol`.
* Confirm that referenced tables and columns are downloaded to Dsync before using a lookup or scan.
* Remove credentials, private endpoints, and tenant-specific secrets from the JSON.

## Troubleshooting

| Symptom                                     | Check                                                                                 |
| ------------------------------------------- | ------------------------------------------------------------------------------------- |
| The function does not appear                | Check the setup columns, JSON validity, and top-level `category` and `form` keys.     |
| The function appears in the wrong category  | Move the value to lowercase `category` inside `Function JSON`.                        |
| The function appears at the end of the list | Add an integer `order`; the default is `9999`.                                        |
| A field is visible but does not submit      | Check its `postTargetCol`, component type, visibility, and required reference fields. |
