|
| 1 | +# Mendix Nanoflow Skill |
| 2 | + |
| 3 | +This skill provides guidance for writing Mendix nanoflows in MDL syntax. Nanoflows share syntax with microflows but execute client-side with restricted capabilities. |
| 4 | + |
| 5 | +## When to Use This Skill |
| 6 | + |
| 7 | +Use this skill when: |
| 8 | +- Writing CREATE NANOFLOW statements |
| 9 | +- Debugging nanoflow validation errors |
| 10 | +- Understanding nanoflow restrictions vs microflows |
| 11 | + |
| 12 | +## Key Differences from Microflows |
| 13 | + |
| 14 | +| Aspect | Microflow | Nanoflow | |
| 15 | +|--------|-----------|----------| |
| 16 | +| **Execution** | Server-side | Client-side (browser/mobile) | |
| 17 | +| **Database access** | Full | No direct access | |
| 18 | +| **Transactions** | Supported | Not supported | |
| 19 | +| **Java actions** | Supported | Not supported | |
| 20 | +| **JavaScript actions** | Not supported | Supported | |
| 21 | +| **File downloads** | Supported | Not supported | |
| 22 | +| **Error handling** | Full `ON ERROR` blocks | Per-action `ON ERROR` supported; `ErrorEvent` (raise error) forbidden | |
| 23 | +| **Offline** | Not available | Available | |
| 24 | + |
| 25 | +## Nanoflow Structure |
| 26 | + |
| 27 | +```mdl |
| 28 | +/** |
| 29 | + * Nanoflow description |
| 30 | + * |
| 31 | + * @param $Parameter1 Description |
| 32 | + * @returns Description of return value |
| 33 | + */ |
| 34 | +CREATE [OR MODIFY] NANOFLOW Module.NAV_Name ( |
| 35 | + $Parameter1: type |
| 36 | +) |
| 37 | +RETURNS ReturnType AS $Result |
| 38 | +FOLDER 'FolderPath' |
| 39 | +BEGIN |
| 40 | + -- Nanoflow logic here |
| 41 | + RETURN $Result; |
| 42 | +END; |
| 43 | +``` |
| 44 | + |
| 45 | +## Naming Convention |
| 46 | + |
| 47 | +Nanoflow names use the `NAV_` prefix by convention: |
| 48 | +- `NAV_ValidateCart` — client-side validation |
| 49 | +- `NAV_ShowDetails` — page navigation |
| 50 | +- `NAV_ToggleFilter` — UI state toggle |
| 51 | + |
| 52 | +## Supported Activities |
| 53 | + |
| 54 | +### Object Operations (in-memory only) |
| 55 | +```mdl |
| 56 | +$Item = CREATE Sales.CartItem (Quantity = 1); |
| 57 | +CHANGE $Item (Quantity = $Item/Quantity + 1); |
| 58 | +``` |
| 59 | + |
| 60 | +### Calling Other Flows |
| 61 | +```mdl |
| 62 | +$Result = CALL NANOFLOW Sales.NAV_ValidateCart (Cart = $Cart); |
| 63 | +$ServerResult = CALL MICROFLOW Sales.ACT_SubmitOrder (Order = $Order); |
| 64 | +$JsResult = CALL JAVASCRIPT ACTION MyModule.MyJsAction (Param = $Value); |
| 65 | +``` |
| 66 | + |
| 67 | +### UI Activities |
| 68 | +```mdl |
| 69 | +SHOW PAGE Sales.CartDetail ($Cart = $Cart); |
| 70 | +CLOSE PAGE; |
| 71 | +VALIDATION FEEDBACK $Item/Quantity MESSAGE 'Quantity must be at least 1'; |
| 72 | +``` |
| 73 | + |
| 74 | +### Logging and Variables |
| 75 | +```mdl |
| 76 | +LOG INFO 'Cart updated with ' + toString($ItemCount) + ' items'; |
| 77 | +DECLARE $IsValid Boolean = true; |
| 78 | +SET $IsValid = false; |
| 79 | +``` |
| 80 | + |
| 81 | +### Control Flow |
| 82 | +```mdl |
| 83 | +IF $Cart/ItemCount = 0 THEN |
| 84 | + VALIDATION FEEDBACK $Cart/ItemCount MESSAGE 'Cart is empty'; |
| 85 | + RETURN false; |
| 86 | +ELSE |
| 87 | + SHOW PAGE Sales.Checkout ($Cart = $Cart); |
| 88 | + RETURN true; |
| 89 | +END IF; |
| 90 | +``` |
| 91 | + |
| 92 | +## Disallowed Activities |
| 93 | + |
| 94 | +These will produce validation errors (12 case branches covering 22 action types in `nanoflow_validation.go`): |
| 95 | +- `ErrorEvent` / `RAISE ERROR` — not available in nanoflows |
| 96 | +- `CALL JAVA ACTION` — Java actions cannot run client-side |
| 97 | +- `EXECUTE DATABASE QUERY` — direct SQL requires server |
| 98 | +- `CALL EXTERNAL ACTION` — external actions are server-side |
| 99 | +- `SHOW HOME PAGE` — home page navigation is server-side |
| 100 | +- `CALL REST SERVICE` / `SEND REST REQUEST` — REST calls are server-side |
| 101 | +- `IMPORT FROM MAPPING` / `EXPORT TO MAPPING` — mapping operations are server-side |
| 102 | +- `TRANSFORM JSON` — JSON transformations are server-side |
| 103 | +- `DOWNLOAD FILE` — file downloads require server-side processing |
| 104 | +- All **workflow actions** (11 types: CallWorkflow, OpenWorkflow, SetTaskOutcome, OpenUserTask, etc.) |
| 105 | + |
| 106 | +**Note:** Object operations (CREATE, CHANGE, COMMIT, DELETE, RETRIEVE) ARE allowed in nanoflows — they operate in-memory on the client. |
| 107 | + |
| 108 | +## Return Type Restrictions |
| 109 | + |
| 110 | +Binary return type is NOT allowed in nanoflows. |
| 111 | + |
| 112 | +## Security (GRANT/REVOKE) |
| 113 | + |
| 114 | +```mdl |
| 115 | +GRANT EXECUTE ON NANOFLOW Shop.NAV_Filter TO Shop.User, Shop.Admin; |
| 116 | +REVOKE EXECUTE ON NANOFLOW Shop.NAV_Filter FROM Shop.User; |
| 117 | +``` |
| 118 | + |
| 119 | +## Management Commands |
| 120 | + |
| 121 | +```mdl |
| 122 | +SHOW NANOFLOWS |
| 123 | +SHOW NANOFLOWS IN MyModule |
| 124 | +DESCRIBE NANOFLOW MyModule.NAV_ShowDetails |
| 125 | +DROP NANOFLOW MyModule.NAV_ShowDetails; |
| 126 | +MOVE NANOFLOW Sales.NAV_OpenCart TO FOLDER 'UI/Navigation'; |
| 127 | +``` |
| 128 | + |
| 129 | +## Common Mistakes |
| 130 | + |
| 131 | +1. **Using Java actions** — Use CALL JAVASCRIPT ACTION instead. |
| 132 | +2. **Using ErrorEvent** — Nanoflows cannot raise errors directly. Handle errors per-action with ON ERROR. |
| 133 | +3. **Expecting transactions** — Nanoflows have no rollback. Design for idempotency. |
| 134 | +4. **File operations** — DOWNLOAD FILE is server-only. |
| 135 | +5. **Binary return types** — Not supported in nanoflows. |
| 136 | +6. **REST/external calls** — REST calls and external actions are server-only. |
| 137 | + |
| 138 | +## Validation Checklist |
| 139 | + |
| 140 | +- [ ] No ErrorEvent / raise error |
| 141 | +- [ ] No Java action calls |
| 142 | +- [ ] No REST calls, external action calls, or database queries |
| 143 | +- [ ] No file download operations |
| 144 | +- [ ] No import/export mapping or JSON transformation |
| 145 | +- [ ] No workflow actions |
| 146 | +- [ ] No show home page |
| 147 | +- [ ] No binary return type |
| 148 | +- [ ] Parameters and return types are nanoflow-compatible |
| 149 | +- [ ] JavaDoc documentation present |
| 150 | +- [ ] NAV_ naming prefix used |
0 commit comments