Cosmocloud Build Documentation
DocumentationTutorials
  • Welcome to Cosmocloud
  • Getting Started
    • 1. Organisations
    • 2. Projects
    • 3. Connect your Database
    • 4. Create Database Models
    • 5. Create APIs
    • 6. Testing Free Tier APIs
  • Free Tier
    • Connecting with MongoDB Data APIs
  • Templates
    • CRUD APIs
    • Entity Search APIs
    • Fetch / Upload Media APIs
  • Examples - How To?
    • Making an external API call
    • Reusable Flows - SubFlows
    • Creating Custom Error Responses
    • Flow Builder - Building Conditional Logics
    • Flow Builder - Utilising Loops
    • Creating Dynamic Queries
    • Accessing Auth Tokens in APIs
    • How to upload/download media in Object Storage
  • Resources
    • APIs
      • Checking Logs
    • SubFlows
    • Models
      • Building Models
    • Environments
      • Environment Tier Types
    • Secrets
      • Custom Secrets
    • Databases
    • Releases
    • Vector Search
      • Create a Vector Search Index
      • Edit a Vector Search Index
      • Delete a Vector Search Index
    • Document Search
      • Full Text Search
        • Concepts
          • Indexing in full-text search
          • Data processing using Analyzers
        • Create a Search Index
        • Creating a Custom Analyzer
        • Full Text Search FAQ
      • Vector Search
    • Object Storage
  • Flow Builder
    • Node Types
      • Trigger Nodes
        • HTTP Response
      • Conditional Nodes
        • If Else
        • If Else V2
        • Switch Case
      • Crypto Nodes
        • PBKDF2 Hmac Hash
      • Debug Node
      • Database Nodes
        • Delete One
        • Delete Many
        • Fetch By ID
        • Find One
        • Find Many
        • Insert One
        • Insert Many
        • List Records
        • Run Aggregation Pipeline
        • Update One
        • Update by ID
        • Update Many
      • External Nodes
        • Fire Events (SQS)
        • API Call
        • Delete storage objects
        • Execute SubFlow
        • Get Presigned URL
        • Post Presigned URL
        • Send EMAIL (SES)
        • Send SMS (SNS)
      • Loop Nodes
        • For loop
        • While loop
      • Variable Nodes
        • Arrays
          • Append array
          • Contains
          • Check array empty
          • Extend array
          • Get Array Item
          • Length of array
          • Reverse array
          • Sort array
        • Date and Time
          • Set current datetime
        • Strings
          • Append String
          • Concat Strings
          • Convert to String
          • Length of String
          • Slice String
          • Split String
          • String Operations
          • To Lower
          • To Upper
          • Trim String
        • Mathematical
          • Add Variable
          • Complex Math Expr
          • Decrement Variable
          • Divide Variable
          • Increment Variable
          • Multiply Variable
          • Subtract Variable
        • JSON
          • Build JSON Object
          • Merge JSON Objects
          • Object to String
          • Update JSON Object
        • Special
          • Build Map
          • Set Variable
          • Exists Check
    • Node name
    • CQL - Cosmocloud Query Language
      • Building Expressions
        • $abs
        • $add
        • $addDate
        • $arrayElemAt
        • $avg
        • $buildDateTime
        • $buildMap
        • $ceil
        • $cond
        • $divide
        • $floor
        • $getDay
        • $getHour
        • $getMinute
        • $getMonth
        • $getSecond
        • $getYear
        • $ifNull
        • $max
        • $min
        • $mod
        • $multiply
        • $pow
        • $subtract
        • $sqrt
      • Building Conditions
        • Compound Operators
          • $and
          • $or
        • Conditional Operators
          • $eq
          • $gt
          • $gte
          • $lt
          • $lte
          • $neq
      • Magical Autocomplete
  • Advanced Guide
    • Configuring Authentication
      • SSO Providers
        • AWS Cognito
      • Authentication Concepts
    • MongoDB Query Language
      • Limitations
    • Performance Considerations
      • Instant Deployments
  • User Management
  • Billing and Payments
    • Billing Portal
  • Help & Support
  • References
    • Change log
    • Available Cloud & Regions
Powered by GitBook
On this page
  • Working with FOR Loop Node
  • Assumptions
  1. Examples - How To?

Flow Builder - Utilising Loops

PreviousFlow Builder - Building Conditional LogicsNextCreating Dynamic Queries

Last updated 10 months ago

Working with FOR Loop Node

In many scenarios, you need to iterate over a collection of items and perform specific actions for each item. This is where FOR loop nodes become essential in Cosmocloud's flow builder.

Imagine you have a list of marks scored by a student and you want to calculate the total marks scored by the student. Here's how you can do it in Cosmocloud's flow builder:

Assumptions

  • You already have an API configured and a request body model configured with it which accepts marks as an array of floats.

Now, let's see how we can leverage the for loop node for iterating through the array of marks and getting the total marks of the student.

  1. Click Add Node, and select the Length of Array node. This will help us get the length of the array which will be useful for iterating through the loop. Configure this node with a variable name of len and pass in the array for which we need the length, as shown in the figure below.

  1. Now lets add a Set Variable node, this variable will be our iterator and help us fetch the marks at different positions in the array. Configure this node as shown in the figure below.

  1. Now let's add the For Loop node to iterate through the marks array. To configure this node we need to specify the variable we will be using to loop through the array, the condition when we want to get out of the for loop and the increment factor by which our variable should be incremented after each iteration. Configure the Variables to use field and the Increment factor field as shown in the figure below.

  1. Now let's add the condition, click on the Edit condition button and inside the JSON editor add the following condition.

5. Let's get inside the for loop click on the Get inside icon. You now are inside the for loop's flow and we will now create a flow here which we want to execute inside the for loop.

  1. Here we first use the Get Array Item node to get the item at a particular index, let's name it item.

  1. Now that we have the item, let's add it to our variable total using the `Add Variable` node.

  1. This is what our flow inside the for loop look like:

  1. Finally, let's return the total marks scored by the student by configuring the `HTTP Response` node as follows:

  1. This is what our entire flow look like:

  1. Let’s now hit this API with postman.

To learn about how to set up APIs .

To learn about how to set up a request body model

To learn more about the For Loop node

click here
click here
click here