# Running Data Flows in Portals

Data Grid Portal Pages provide a way for Portal users to interact with said [AirData App Objects](../../working-with-data/airdata/airdata-app-objects) in various pre-approved ways. One of the most powerful ways Portal viewers can interact with data in a Data Grid is by running [Data Flows](../../studio/data-flows) on select App Object instances.

## Prerequisites: [App Object](https://github.com/airkit/airkit-docs/blob/master/docs/v17-15/airdata-app-objects.md-AirData-App-Objects) and Portal Data Grid pages

In order to run a Data Flow on App Objects displayed in a Data Grid Portal Page, you must first have access to both an App Object and a Data Grid Portal Page that displays said App Object.

### Creating an App Object

App Objects are defined in the [Data Builder](../../studio/builder-bar/data-builder). There are no constraints to the type of App Object you need to create here: they can have any number of properties, which themselves might be any [primitive type](../../variable-data-types/data-types-overview) or even other App Objects. Once the structure of an App Object has been fully described, make sure to save your application so that the rest of the application will have access to the App Object you just defined.

For a deeper dive into how to create App Objects and how they might connect to they rest of your application, check out [Building Your First App](../../welcome/building-your-first-app).&#x20;

### Creating a Data Grid Portal Page

A Data Grid Portal Page displays a table of data stored in [AirData](../../working-with-data/airdata); each Data Grid must be associated with a particular App Object. You can select which App Object you want your Data Grid to display from a dropdown menu in the [Inspector](../../studio/builder-bar/portal-builder). Select the App Object you intend to display and run [Data Flows](../../studio/data-flows) on.

For more on how to create a Data Grid Portal Page that displays a particular App Object, check out the documentation on [Portal Builder](../../studio/builder-bar/portal-builder).&#x20;

## Step 1: Build out your Data Flow

[Data Flows](../../studio/data-flows) that can be run through a Data Grid Portal Page are built out in the same way as any other Data Flow: in the [Connection Builder](../../studio/builder-bar/connection-builder), using all the same [Data Operations](../../data-operations/data-operation-overview).

There are only two constraints to keep in mind while constructing Data Flows intended run from a Data Grid.

Firstly, when a Data Flow is run from a Data Grid, there is no designated place for resulting output to be displayed. Data Flows that are run from a Data Grid are intended to connect with external systems – [send emails](../email/sending-email-from-airkit), update a database, activate [Chat Bots](../voice-and-chat/chat-bot-basics) – not return output. While the Portal Builder does not forbid incorporating a Data Flow that returns some output, it must be understood that whatever output it returns will not be accessible in practice. If you want to run a Data Flow that displays new information within a Data Grid, it is necessary to build a place for that desired information within the displayed App Object and then run an [Airdata query](https://github.com/airkit/airkit-docs/blob/master/docs/v17-15/airdata.md-querying-capabilities) as part of the incorporated Data Flow.

Secondly, the input required by the Data Flow must be structured appropriately. Once a Data Flow is built into a Portal Page, it can only be fed input in the form of selected App Object instances, and the structure of the Data Flow being run must reflect that.

This means that the Data Flow can only accept input structured in two ways:

1. The App Object that is being displayed in the Data Grid
2. A [List](../../variable-data-types/the-list-data-type) of said App Objects

<details>

<summary>How do Data Flows that have been incorporated into a Data Grid parse input?</summary>

\


The above section specified that a [Data Flow](../../studio/data-flows) created to run from a Data Grid Portal Page can accept input in two forms: a singular [App Object](https://github.com/airkit/airkit-docs/blob/master/docs/v17-15/airdata-app-objects.md-AirData-App-Objects), or a singular [List](../../variable-data-types/the-list-data-type) of App Objects (when, in both cases, all pertinent App Objects match the App Object being displayed in the Data Grid).

Note that App Object instances are selected by clicking on the check box to immediate left of the row that displays the desired instance:

![organizing info](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-d9bbe229730d71feea3eee78ca0879044b6b27e1%2Frunning-data-flows-in-portals-v1715-0.gif?alt=media)

However, while input is always given in this way, how the input is parsed depends on the format of input accepted by the Data Flow.

**When a Data Flow accepts a a single App Object as input**, it will run on every selected App Object instance individually. That is, it will run the Data Flow repeatedly: once for every app object instance selected. For instance, let's say that the Data Flow in the above example (ostensibly one that sends a follow up email) functions this way. It accepts a single App Object (or a "Feedback Object") as input, and runs twice: first it runs and sends an email to leo@airkit.com, and then it runs again and sends another email to chandra@airkit.com.

**When a Data Flow accepts a List of App Objects as input**, it will run only once, on a List generated from every selected App Object Instance. If we now assume that the above example functions this way, the input given into the Data Flow would look as follows:&#x20;

```json
[  
 {  
  "Email": "leo@airkit.com",   
  "Feedback": "It's okay.",   
  "Notes": "Need to follow up",   
  "Resolved": FALSE  
 },   
 {  
  "Email": "chandra@airkit.com",  
  "Feedback": "It's great!",   
  "Notes": "Need to follow up",   
  "Resolved": FALSE  
 }  
]
```

Data Flows that accept input in this way ought to be used exclusively in cases where the Data Flow requires multiple App Object instances in order to function as intended, such as in cases where properties of App Object instances need to be directly compared. While it is possibly to craft a Data Operation that repeatedly loop through a list of App Object instances and does the same thing to each of them, this introduces an extra layer of complication that ought to be avoided when possible.

</details>

## Step 2: Add the Data Flow to the Portal Page

Once you've built out a [Data Flow](../../studio/data-flows) that meets the [constraints](#h_01FCP9B4GKYV2YBV4B5Y7MHY7P) given above, save your application and toggle over to the [Portal Builder](https://github.com/airkit/airkit-docs/blob/master/docs/v17-15/portal-builder.md-Portal-Builder). (Saving your application ensures Portal Builder will have access to the Data Flow you just created.) [Access your Data Grid](../portal-capabilities#h_01FCPJYGPV6KEWXDCKVGY3S8F7) and click on the "Add Data Flow" button in the Inspector, nested under Data Flow. From there, you can select which Data Flow you want from a dropdown menu of relevant Data Flows (that is, Data Flows that accept input in one of the [required formats](#h_01FCP9B4GKYV2YBV4B5Y7MHY7P)):

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-01fb9b612c234f682459bf3c96d9a661ad020cf9%2Frunning-data-flows-in-portals-v1715-1?alt=media).gif)

After selecting a Data Flow to associate with the Data Grid, label the button that will run the Data Flow from the Data Grid. Multiple Data Flows can be added to a single Data Grid, so it's important to give each button a unique name that tells Portal users important information regarding the Data Flow that the button will trigger:

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-01fb9b612c234f682459bf3c96d9a661ad020cf9%2Frunning-data-flows-in-portals-v1715-2?alt=media).gif)

## Step 3: Publish and Test

Most components of an app build can be fully emulated by [Previewing](../../studio/app-preview) the app, but this is not the case with Portals, because Portals aren't part of an app proper; they're a tool for internal (though non-developer) users as opposed to app users.&#x20;

In order to test and confirm that a [Data Flow](../../studio/data-flows) built into a Data Grid is running as intended, you'll need to [publish your app](../publishing/publishing-your-application) and the access the Portal by then accessing the URL associated with the Portal in [Configuration Builder](../../studio/builder-bar/configuration-builder). For more on how to associate URLs with your organization, check out [Connecting your Domain to Airkit](../../customizations/connecting-your-domain), and for more on how to access a published Portal Page, check out [Accessing Portal Pages](../portal-capabilities#h_01FCPJYGPV6KEWXDCKVGY3S8F7).

Upon accessing the Data Grid Portal Page in question, you should see the button associated with Data Flow in the upper right corner. Note that the label on the button matches the label you gave it in the Portal Builder Inspector:

![organizing info](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-fa902c2d6a2529c58063e07a668156073e0c2f00%2Frunning-data-flows-in-portals-v1715-3.png?alt=media)

When multiple Data Flows are associated with a single Data Grid, the buttons will be arranged as follows:

![organizing info](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-b5c701709422853da4e138539e3fa97ad7284a9f%2Frunning-data-flows-in-portals-v1715-4.png?alt=media)

Now you can run your Data Flows on any number of your saved App Objects! Simply select them by clicking on the check box to the left of the relevant object or objects, and then click on the button indicating the Data Flow you want to run:

![organizing info](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-2ef875a30d7b8deb34b2012b2de0c9ba38435890%2Frunning-data-flows-in-portals-v1715-5.gif?alt=media)
