cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Community Support Team
Community Support Team

Re: Nested Loops and API calls

Hi @jernejp ,

Do you want to use the AddedActivity (rather than AllActivities) within yout second loop?

 

Based on the needs that you mentioned, I afraid that a triple nested loop could not achieve your needs. Please consider take a try with above solution I provided.

 

On your side, you could consider create a ForAll loop firstly to retrieve all added activities using the following formula:

 

ForAll(
    AllActivities;
    Collect(
        AddedActivity;
        'MyApi'.AddActivitiesToBusinessPartner(
            {
	    }
        )
    )
)

Then add another ForAll loop to go through the all attendees that attended the activity, and add them to above retrieved added activities using following formula:

 

 

ForAll(
         AddedActivity,
         ForAll(
                Filter(
                        '[dbo].[attendees]';
                        activity_id = AddedActivity[@id]
                );
                'MyApi'.AddAttendantsToAnExistingActivity(
                {
                  ....
                }
              )
         )
)

 

So your whole formula should look like below:

ForAll(                   /* <-- Seperated ForAll Loop */
    AllActivities;
    Collect(
        AddedActivity;
        'MyApi'.AddActivitiesToBusinessPartner(
            {
	    }
        )
    )
);;
ForAll(                          /* <-- Nested ForAll Loop */
         AddedActivity;
         ForAll(
                Filter(
                        '[dbo].[attendees]';
                        activity_id = AddedActivity[@id]
                );
                'MyApi'.AddAttendantsToAnExistingActivity(
                {
                  ....
                }
              )
         )
)

Please take a try with above solution, check if the issue is solved.

 

Best regards,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
jernejp
Level: Powered On

Re: Nested Loops and API calls

Hi @v-xida-msft 

 

The problem is, that in my AllActivities, the ID of activity would be (for example) 60 (as it's taken from my database), but from ERP, the response is an id of (for example) 4000231. So If I understand correctly, the second (nested) loop wouldn't work, because 'activity_id' is not the same as AddedActivity[@id].

Could I add a column to AddedActivity in the first loop, and add AllActivities[@id] to it? How would I go about that? I think if I can add the database's ID of activity to AddedActivity, then the second loop would be finished, right?
Hope I'm making sense

Highlighted
Community Support Team
Community Support Team

Re: Nested Loops and API calls

Hi @jernejp ,

Yeah, you are right. I have made a test on my side, please consider take a try with the following formula:

ForAll(                   /* <-- Seperated ForAll Loop */
    AllActivities;
    Collect(
        AddedActivity;
        {
ActivityID: AllActivities[@id], /* <-- add a column to store the id value from the AllActivities */
ResponseRecord: 'MyApi'.AddActivitiesToBusinessPartner( { ... } )
} ) );; ForAll( /* <-- Nested ForAll Loop */ AddedActivity; ForAll( Filter( '[dbo].[attendees]'; activity_id = AddedActivity[@ActivityID] ); 'MyApi'.AddAttendantsToAnExistingActivity( { .... } ) ) )

Please consider take a try with above formula, check if it could help in your scenario.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

jernejp
Level: Powered On

Re: Nested Loops and API calls

Oh my god, THANK YOU SO MUCH! IT WORKS!

jernejp
Level: Powered On

Re: Nested Loops and API calls

[EDIT] Removed the post, as it was working. The problem was with my internet connection apparently. 

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (8,526)