cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Alaa-Alarori
Helper II
Helper II

Add delay to the code

Hello there,

 

Context:

I have two local connections that I am patching when the phone gets internet.

first collection contains general information about a family. second collection contains information about the family's members.

during data collection I assign a serial number to each family and use the same one to its members.

 

to patch the colelctions to SharePoint, I go through a first ForAll loop and inside a go again to a second ForAll loop. 

 

my problem:

becuase the data in the first colelction is too much (around 70 columns) it seems that it's taking a bit of time to update the first SharePoint list which is resulting with wrong Serial Number assigned to the family members (the previous instead of the new)

 

my question:

can I add dealy to the code so I give SharePoint a second before patching the second collection

 

other suggestions are welcome, and here is a snippet of the code I am using

thanks,

Alaa

 

 

ForAll(
    LocalCAT,  Patch(CAT, Defaults(CAT),
                        {
                            HHID: First(SortByColumns(CAT,"HHID",Descending)).HHID + 1,
                         ... the rest of the fields (around a 70 fields)
                        });
    ForAll(
        Filter(
            LocalHouseholdMembers,
            HHID = LocalCAT[@HHID]
        ),
        Patch(HouseholdMembers, Defaults(HouseholdMembers),
            {
                HHID: First(SortByColumns(CAT,"HHID",Descending )).HHID,
              ... the rest of the fields
            }
        )
    )

3 REPLIES 3
PaulD1
Super User
Super User

To create a delay, you can use a timer control, but I don't think that is going to help you with an embedded ForAll loop.

If I can ask, why are you using an embedded ForAll? As you have already assigned your joining IDs within the App, you don't need to retrieve the SharePoint assigned ID or anything like that. Can you just:

Collect(CAT, LocalCat);
Collect(HouseholdMembers,LocalHouseholdMembers)

It isn't 'transactional' so if writing to CAT succeeds and writing to HouseholdMembers fails half way through, you'll end up with some CAT records missing their children, but if you want that sort of control you really want to be using Azure SQL DB and stored procedures.

v-xida-msft
Community Support
Community Support

Hi @Alaa-Alarori ,

Could you please share a bit more about your scenario?

 

Based on the formula you provided above, I could not find any syntax error with it. If you want to add a Delay logic to your formula, I afraid that there is no way to achieve your needs in PowerApps currently.

 

On your side, please consider modify your formula as below:

 

ForAll(
      LocalCAT,  
Collect( /* <-- Using Collect function to submit your data into your SP Lists */
CAT, { HHID: First(SortByColumns(CAT,"HHID",Descending)).HHID + 1, ... the rest of the fields (around a 70 fields) }
); ForAll( Filter( LocalHouseholdMembers, HHID = LocalCAT[@HHID] ), Collect(
HouseholdMembers, { HHID: First(SortByColumns(CAT,"HHID",Descending )).HHID, ... the rest of the fields } ) )
)

 

Or you could consider modify your formula as below:

ClearCollect(
               SavedCATRecords,
               ForAll(
                      LocalCAT,  
                      Patch(
                            CAT, 
                            Defaults(CAT),
                            {
                               HHID: First(SortByColumns(CAT,"HHID",Descending)).HHID + 1,
                               ... the rest of the fields (around a 70 fields)
                            }
                      )
               )
);
ForAll(
SortByColumns(SavedCATRecords, "HHID", Descending), ForAll( LocalCAT, ForAll( Filter(LocalHouseholdMembers, HHID = LocalCAT[@HHID]), Patch( HouseholdMembers, Defaults(HouseholdMembers), { HHID: SavedCATRecords[@HHID], ... the rest of the fields } ) ) )
)

Please consider take a try with above solution, then check if the issue is solved. Also please consider use the Collect function to patch data into your SP list instead of the Patch function.

 

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.
Anonymous
Not applicable

Hi @Alaa-Alarori how are you progressing with this? Were the above replies helpful?

 

@Anonymous 

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,061)