Nanoflows

Last modified: January 11, 2024

1 Introduction

Nanoflows are similar to microflows, in that they allow you to express the logic of your application. However, they do have some specific benefits (for example, they run directly on the browser/device and can be used in an offline app). Furthermore, most of the actions run directly on the device, so there is also a speed benefit for logic which does not need access to the server.

This page is an overview of all the elements that can be used in a nanoflow. For the properties of the nanoflow itself, see Nanoflow Properties.

For information on using nanoflows as data sources, see Nanoflow Source.

2 When to Use Nanoflows

2.1 Offline Mobile Apps

Nanoflows are designed with offline-first applications in mind, as they allow you to model application logic that works in offline apps. Since all database-related actions will be executed on the local offline database, nanoflows in offline apps will be fast.

2.2 Logic Where No Connection Is Needed

Nanoflows also offer great value to online applications (for example, for UI logic, validations, calculations, and navigation). However, please keep in mind that, when you perform database-related actions, each action will create a separate network request to the Mendix Runtime.

The following actions interact with the database:

  • Create
  • Commit
  • Retrieve
  • Rollback

Therefore, the best practice is to use nanoflows in online applications when they do not contain the above actions.

2.2.1 Other Cases

Although nanoflows perform best in online applications when no database-related actions are used, and these are generally the best cases, nanoflows that contain at most one database-related action can also still perform well. Because such nanoflows only require one network call, they perform as well as a microflow. An example of such a use case is performing validation logic on an object and committing the object in the same nanoflow.

3 Differences from Microflows

There are five main differences between nanoflows and microflows:

  1. When a nanoflow steps through its actions, client actions are directly executed. For example, an open page action immediately opens a page instead of at the end of the nanoflow. This is different from client actions in a microflow, which only run when the client receives the result from the microflow.
  2. When used in nanoflow activities, expressions do not support the following objects and variables: $latestSoapFault, $latestHttpResponse, $currentSession, $currentUser, $currentDeviceType.
  3. Nanoflows are not run inside a transaction so, if an error occurs in a nanoflow, it will not roll back any previous changes.
  4. Nanoflows and microflows do not provide the same actions. Some actions available in microflows are not available in nanoflows, and vice versa.
  5. Because nanoflows use JavaScript libraries and microflows use Java libraries, there can sometimes be slight differences in the way expressions are executed.
  6. Changes done to the lists in a sub-nanoflow are not reflected in the original nanoflow.

4 Notation and Categories

The graphical notation of nanoflows is based on the Business Process Model and Notation (BPMN). BPMN is a standardized graphical notation for drawing business processes in a workflow.

A nanoflow is composed of elements. The following categories are used:

  • Events represent the start and endpoints of a nanoflow and special operations in a loop
  • Flows form the connection between elements
  • Decisions deal with making choices and merging different paths again
  • Activities are the actions that are executed in a nanoflow
  • Loop is used to iterate over a list of objects
  • Parameter is data that serves as input for the nanoflow.
  • Annotation is an element that can be used to put comments in a nanoflow.

4.1 Events

Events represent the start and endpoints of a nanoflow and special operations in a loop.

Graphic Name Description
start event
Start event The starting point of the nanoflow. A nanoflow can only have one start event.
end event
End event Defines the location where the nanoflow will stop. Depending on the return type of the nanoflow, in some cases a value must be specified. There can be more than one end event.
continue event
Continue event Used to stop the current iteration of a loop and continue with the next iteration. Continue events can only be used inside a loop.
break event
Break Event Used to stop iterating over the list of objects and to continue with the rest of the flow after the loop. Break events can only be used inside a loop.

4.2 Flows

Flows form the connection between elements.

Graphic Name Description
Sequence flow An arrow that links events, activities, decisions, and merges with each other. Together they define the order of execution within a nanoflow.
Annotation flow A connection that can be used to connect an annotation to another element.

4.3 Decisions

Decisions deal with making choices and merging different paths.

Graphic Name Description
decision
Decision Makes a decision based on a condition and follows one and only one of the outgoing flows. Note: there is no parallel execution in nanoflows.
merge
Merge Can be used to combine multiple sequence flows into one. If a choice is made in a nanoflow and afterwards some common work needs to be done, you can combine the two (or more) paths using a merge.

4.4 Activities

Activities are the actions that are executed in a nanoflow:

Activity

4.5 Loop

A loop is used to iterate over a list of objects:

Loop

For every object the flow inside the loop is executed. A loop activity can contain all elements used in nanoflow, with the exception of start and end events.

4.6 Parameter

A parameter is data that serves as input for the nanoflow.

Parameter

Parameters are filled at the location from where the nanoflow is triggered.

4.7 Annotation

An annotation is an element that can be used to put comments in a nanoflow:

Annotation

4.8 Item Usages

Studio Pro visualizes which items are used by the selected element (or elements). It does this by showing the used items in white text on a blue background. Conversely, elements that use the item (or items) returned by the selected element (or elements) are marked with the word ‘Usage’ in white text on a green background.

In the example below, the parameter AccountPasswordData is highlighted because it is used in the selected activity (Retrieve Account). And the activity Save password has a Usage label because it uses the object returned by Retrieve Account.

5 Keyboard Support

5.1 Studio Pro 10.6 and Above

The tables in the following sub-sections present the shortcut keys that can be used for navigating and manipulating nanoflows in the nanoflow editor in Studio Pro 10.6 and above.

5.1.1 Selection

Key Effect
Arrow Keys Select nearby element (activity, event, loop or parameter) in the direction of the arrow.
Home Select the start event.
End Select the first end event.
Ctrl + a Select all elements.
Tab If a loop is selected, the first element inside the loop will be selected.
Shift + Tab If an element inside a loop is selected, the loop itself will be selected.

5.1.2 Navigation

Key Effect
mouse scroll Scroll up/down.
Shift + mouse scroll Scroll left/right.
Space + mouse button Drag screen.
Ctrl + +/- Zoom in/out.
Ctrl + 0 Reset zoom level to 100%.
Ctrl + mouse scroll Zoom in/out.

5.1.3 Element Manipulation

Key Effect
Enter - on an element If an element is selected, edit its properties.
Enter - on a flow arrow If a flow arrow is selected, open the Logic Bot dialog box.
Enter - on a Logic Bot suggestion list item The selected item is added on the flow arrow. The Logic Bot dialog box is shown again for the next action to be added.
Shift + Enter (or Shift + mouse click) - on a Logic Bot suggestion list item The selected item is added on the flow arrow. The element’s property dialog box is opened.
F2 Rename the variable returned by the selected element.
Shift + F2 Edit the caption of the selected element.
Context-menu key Open the context-menu for the currently selected element.

5.2 Studio Pro 10.5 and Below

The nanoflow editor offers keyboard support for navigating and manipulating nanoflows. The following table shows the shortcut keys that can be used in the nanoflow editor in Studio Pro 10.5 and below.

Key Effect
Arrow keys Move the selection box to the activity or element in the direction of the arrow key. For example, if currently a show page activity is selected and you press the right arrow key, the activity to the right of it becomes selected.
Enter Edit the properties of the selected element.
F2 Edit the name of the return value of the selected activity. This shortcut only functions on activities that return a result.
Shift + F2 or just start typing Edit the caption of the selected element.
Ctrl + arrow keys Move the selected element in the direction of the arrow.
Tab If a loop is selected, the first element inside the loop will be selected.
Shift + Tab If an element inside a loop is selected, the loop itself will be selected.
Home Select the start event.
End Cycle through the end events.
Shift By holding Shift when resizing an activity, it will stay centered at its current position and expand equally in all directions.
Ctrl When pressing the Ctrl, you can select additional activities. Clicking a selected component while holding Ctrl will deselect it.
Context-menu key or Shift + F10 Open the context-menu for the currently selected element.

6 Security

Nanoflows are executed in the context of the current user. Any operation for which the user is unauthorized will fail. For instance, when objects are retrieved in a nanoflow, only the ones for which the current user has read access will be returned. Committing an object only succeeds when the current user has write access for all changes.

7 Converting a Nanoflow to a Microflow

To convert a nanoflow to a microflow, you have two options. The first option is to right-click anywhere in the nanoflow editor and select Convert to microflow. Alternatively, in the App Explorer, right-click on the name of the nanoflow you want to convert, and select Convert to microflow.

Convert to microflow

A new microflow is created and added to the same directory, and you can get consistency errors if there are actions that are not supported by microflows.

8 Canvas Interaction

In the nanoflow editor from Studio Pro 10.6, you can use common patterns like unlimited canvas, enhanced zoom and scroll, and a snap-to-flow to make new activities from the toolbox and toolbar always well aligned in your flow.