Bhubaneswar, Odisha, India
+91-8328865778
support@softchief.com

Working with Do Until Loop in Power Automate with JSON and Array

Working with Do Until Loop in Power Automate with JSON and Array

In this example, you will come to know how to use Do until loop in Power Automate when you want to run LOOP for a specific condition met.

Scenario:

Need to Build a Flow which will get JSON response from a Third Party Web API request called as Currency Layer to get Live Exchange Rates and push the response in Dataverse table using loop.

Solution:

Step 1 – Design Table

Create a New table called as “Realtime Currency Exchange Rates” and add 3 columns Source Currency, Target Currency both are string and last column as Exchange Rate as decimal.

Step 2 – Design Flow

Now configure a flow to run everyday to pull data from external app and push data to Dataverse table.

Sub Step 1 : Add Trigger

Sub Step 2: Initialize a string variable and set the value as Target currency. Currencies should be in command separated and the currency code need to be passed.

Sub Step 3: Initialize an Array variable and set the value to store the currencies with comma splitting for the Target Currency Variable. Use below expression.

split(variables(‘Target Currencies’),’,’)

Sub Step 4: Take another integer variable to work as counter for the loop starts from ZERO.

Sub Step 5: Add a HTTP action to connect the WEB API with URI and use Get method and also pass query strings that are required in the request object. This information you can get from WEB API documentation of that third party app.

The HTTP response is received in JSON format given below.

{
    "success": true,
    "terms": "https://currencylayer.com/terms",
    "privacy": "https://currencylayer.com/privacy",
    "timestamp": 1430401802,
    "source": "USD",
    "quotes": {
        "USDAED": 3.672982,
        "USDCHF": 57.8936,
        "USDCAD": 126.1652,
        "USDPLN": 475.306
    }
}

Sub Step 6 : Add a Parse JSON step to extract properties from the HTTP response JSON

Sub Step 7: Add a Do Until Loop action and in the condition choose, Initial Counter is equal to total row count of Target Currency Array. use the below expression for the condition.

length(variables(‘Array Currencies’))

Sub Step 8: Add an Dataverse “Add a new row” action inside Do Until loop to create a record in the table. For the Exchange Rate column assign Expression as given below.

body(‘Parse_JSON’)?[‘quotes’]?[concat(‘USD’,variables(‘Array Currencies’)[variables(‘Initial Counter’)])]

Sub Step 9: Assign the Target Currency also using Expression.

The expression used is given below.

variables(‘Array Currencies’)[variables(‘Initial Counter’)]

Sub Step 10: Increment the Counter Variable by 1.

Now you can run the result and test. After run then table stores data.

The final Flow looks as below.

The table data shows as below.

Hope this helps.

You can enroll now !We are giving 30% discount on our Internship Program

Don’t miss the chance to participate in the upcoming Internship Program which will be done using Microsoft Dot Net Web Development Full Stack Technology. The new batch will be starting from May 20, 2024.  We will have most experienced trainers for you to successfully complete the internship with live project experience.

Why to choose Our Internship Program?

Industry-Relevant Projects
Tailored Assignments: We offer projects that align with your academic background and career aspirations.
Real-World Challenges: Tackle industry-specific problems and contribute to meaningful projects that make a difference.

Professional Mentorship
Guidance from Experts: Benefit from one-on-one mentorship from seasoned professionals in your field.
Career Development Workshops: Participate in workshops that focus on resume building, interview skills, and career planning.

Networking Opportunities
Connect with Industry Leaders: Build relationships with professionals and expand your professional network.
Peer Interaction: Collaborate with fellow interns and exchange ideas, fostering a supportive and collaborative environment.

Skill Enhancement
Hands-On Experience: Gain practical skills and learn new technologies through project-based learning.
Soft Skills Development: Enhance communication, teamwork, and problem-solving skills essential for career success.

Free Demo Class Available