This is a guide on how to add and test the Query step in a Flow Builder.
Query is an Activity that is used to import data from one app into the other app. This step, when executed at the integration creation, is known as the initial data import. Let’s say you are creating an integration to import and sync your repositories from Github to another app. You will need to import all the existing repositories and their details from the Github account once. This is done through the Query step.
As the data that needs to be fetched from another app can be in a large amount, a Query usually runs in a loop and fetches records in a page-by-page manner. This is known as Pagination. Pagination saves our systems from getting overwhelmed from importing large amounts of data in a single call.
A paginated Query runs like a loop in the Flow. It fetches a page of records and runs all its child steps one by one. It keeps fetching the data until all the pages are exhausted. The Query step usually takes longer to complete than the other steps as it is fetching a large number of records from another app.
Adding a Query Inside a Guided Flow
To add a Query step, create a new Flow or open an already created Flow.
Whenever we need to run a Query at the time of the integration creation, we add it in the Setup App step. The Setup App step runs all its child steps once when the end-user sets up the integration. So before the Query step, you need to add the setup step from the list of steps (shown above).
Step 1: Click on the kebab menu on the Setup app and select Add Child Step.
Step 2: Next, search and select the app you want to add to the Query step. You can select any app that you want to import records from.
Step 3: Click on Select an action or query for this step to open the Activity dropdown and select the Query.
Step 4: Add your app's account from where you want to fetch the records.
Step 5: Any number that you enter in the above field will take the page size of your target app into account. The records will be imported on a page-by-page basis, just like any paginated Query. So your provided number will be rounded off to the nearest page. If you want to import all the records, just leave this field empty, as in the case of the current example.
You can also let the end-user provide the number of records that they wish to import. For this, you will need to create an activity field that will take numeric end-user input. After adding that, the added field will appear in the Query step, as shown below.
Step 6: Click on the field(s), this is where you configure fields for your query. You can manually enter the username here or by clicking on the "+" sign you can add a tag and refer to username from anothe step. In our running example, we'll configure the username field. To learn how to configure field(s) in Activities, visit this guide.
Once you're done configuring your app, click on 'Continue' to proceed.
Step 7: Next, enter the required field values to test your Query. In the running example, we'll enter the username of our Github account. To add dynamic tags in the fields, click on the '+' in front of the text input area. A dropdown menu will open where you can select dynamic tags. Then, click on the 'Test' button to see if your Query is fetching the records.
If the Query is executed successfully, you will start receiving the results, iteration-wise. In this example, since we're fetching our Github repositories, we'll get data for each repository in a single iteration. You can click on each iteration to verify the received data.
In the above image, you can view the details of the first record fetched by the Query. Click on 'Next Page' to bring the next iteration or the next record.
The iterations depend upon the pagination handled in the Connector end for this Query. The number of iterations is equal to the number of pages or records the connected account holds. You can keep on bringing next iterations until all the pages are exhausted and click on 'Done' to save this step.
That's all you need to know to add a Query inside a Guided Flow. Next, you'll learn how to use Loops in Flows with paginated Queries.