Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

ForAll patch only updating first record - incorrectly

(0) ShareShare
ReportReport
Posted on by 236

I have the following 2 collections.
col_TodayChecks : A List of checks have already been done at the site today. The ID_Check field is the primary key in my SQL database.
col_InspectTemplate : A list of all inspections that NEED to be done at a site. ID_Chk is set to 1 by default, but needs to be updated to value of ID_Check mentioned above.

CountRows(col_TodayChecks) will always be <= CountRows(col_InspectTemplate)
and all the records in col_TodayChecks will always exist in col_InspectTemplate.


I have tried both a lookup()

 

ForAll(col_TodayChecks,
 Patch(col_InspectTemplate, LookUp(col_InspectTemplate, ID_Room=ThisRecord.ID_Room And ID_Check_Option=ThisRecord.ID_Check_Option),
 {
 ID_Chk:ThisRecord.ID_Check
 }))

 

and a First(Filter())

 

ForAll(col_TodayChecks,
 Patch(col_InspectTemplate, First(Filter(col_InspectTemplate , ID_Room=ThisRecord.ID_Room And ID_Check_Option=ThisRecord.ID_Check_Option)),
 {
 ID_Chk:ThisRecord.ID_Check
 }));

 

...to update the col_InspectTemplate records once the inspection has been performed.
(I need to do this because I need to reference the col_InspectTemplate collection elsewhere in my app where the ID_Chk <>1)

 

In both cases only the FIRST record in col_InspectionTemplate is being updated.
Also - Despite the lookup/filter the first record does not meet the criteria.

 

Using the monitor, I get a 'success' result on the Filter operation, but the detail returns the following.

{
"status": null,
"duration": 0.19999980926513672,
"dataSource": null,
"responseSize": null,
"controlName": null,
"propertyName": null,
"nodeId": null,
"formulaData": {
"script": "",
"spanStart": null,
"spanEnd": null
},
"data": {
"duration": 0.19999980926513672
}
}

Implying (to me) that its not finding the record?


My understanding is that the above should
Go to the first record in col_TodayChecks then
lookup/filter the col_InspectTemplate collection record that meets the criteria
update the ID_Chk field with the value from the current record from col_TodayChecks
Then move to record 2 in col_TodayChecks before going through the process again. (Until all records in col_TodayChecks have been 'assessed')

 

If I patch the values (ID_Room, ID_Check_Option and ID_Check) from col_TodayChecks, to a temporary collection while inside the ForAll loop, I have confirmed that the values from each record in col_TodayChecks are being identified correctly.

 

Its a pitty that I cannot Set / UpdateContext within the ForAll loop to debug the process.

 

Any ideas appreciated.

 

Categories:
  • MissingLink Profile Picture
    MissingLink 236 on at
    Re: ForAll patch only updating first record - incorrectly

    Thanks @turnerj3  : That is a different way to skin this cat - and it works.

  • Verified answer
    turnerj3 Profile Picture
    turnerj3 2,039 on at
    Re: ForAll patch only updating first record - incorrectly

     

    @MissingLink ,

    This example shows a slightly different syntax in the lookup. It may be worth a try. Instead of ThisRecord it calls the collection.


    ForAll( allRecords, Patch( mySharePointList, LookUp(mySharePointList, ID: allRecords[@ID]), {Status: "Closed"} );

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

End of Year Newsletter…

End of Year Community Newsletter…

Tuesday Tip #12 Start your Super User…

Welcome to a brand new series, Tuesday Tips…

Tuesday Tip #11 New Opportunities…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,609

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,420

Leaderboard