cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
stapes
Impactful Individual
Impactful Individual

ForAll command - how has this worked?

aeroplane mode.JPG

 

I built this canvas app to do stock taking.

The users found it painfully slow, and asked if I could tweak it to speed it up. Probably a poor internet connection inside the fridge.

These are the steps I took to deal with that:

 

Instead of calling a Flow to add each new entry to the SQL database as they go, I added the new lines to a local collection.

Then, when I am done collecting this data, I use another control to do the database update.

I do this using ForAll. (see below).

Then when I execute my ForAll statement, it does exactly the right thing, and only adds the new lines.

My question is: how does it do this?

 

This is the statement:

 

 

 

 

ForAll(
    colStockCounts,
    IPL_AddStockTake.Run(
        ProductCode,
        POR,
        BatchID,
        Unit,
        BinLocation,
        Count,
        User().FullName
    )
);

 

 

 

 

 I was going to add a conditional clause, such as If(IsEmpty(ID), IPL_AddStockTake, but it looks like I might not need to.

 

The test:

Load the App and Navigate to this page.

Turn the devices wi-fi off. The Aeroplane symbol is shown.

Add new lines to the table.

Turn the devices wi-fi back on. Aeroplane symbol goes off.

Click the Tick at the top right to update the DB.

 

7 REPLIES 7
gabibalaban
Dual Super User
Dual Super User

Hi @stapes ,

In translation, this formula means that you are calling a power automate flow for each records in your collection:

ForAll(
    colStockCounts,
    IPL_AddStockTake.Run(
        ProductCode,
        POR,
        BatchID,
        Unit,
        BinLocation,
        Count,
        User().FullName
    )
);

 Of course this approch is a time consumer.

From my understading you want to patch as new records a collection to an SQL table. Is your collecttion has a similar structure as the SQL table ?

If so ... why don't you use directly Patch(datasource, yourcollection) ?

 

Hope it helps !

 

stapes
Impactful Individual
Impactful Individual

@gabibalaban  that wasn't my question. Still, using Patch is an interesting suggestion.

@stapes , can you rephrase your topic, for a better understanding of your isssue ?

stapes
Impactful Individual
Impactful Individual

@gabibalaban 

when I execute my ForAll statement, it does exactly the right thing, and only adds the new lines.

My question is: how does it do this?

@stapes,

ForAll() function iterates through all records of colStockCounts collection (in an unspecified order), for each record the Flow is called. I supose that inside the flow you have an action SharePoint - Create Item. This action does not need an ID value to create new records.  

stapes
Impactful Individual
Impactful Individual

@gabibalaban  - I am wondering why it does not create duplicates of the existing records in the table.

It shouldn't ....as each flow instance called by execution of ForAll() function has it's own values for 

 

        POR,
        BatchID,
        Unit,
        BinLocation,
        Count,
        User().FullName

 

columns, given by the record from collection. 😊 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (2,093)