cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Alaa-Alarori
Level: Powered On

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
Super User
Super User

Re: Add delay to the code

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.

Community Support Team
Community Support Team

Re: Add delay to the code

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.
TopShelf-MSFT
Level 10

Re: Add delay to the code

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

 

@TopShelf-MSFT 

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,833)