web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch function not wor...
Power Apps
Unanswered

Patch function not working with For All and lookup

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

I have a gallery which contains questions and  answers. Each question set is identified by TestIdentifier. E.g if i have a question set of 20 questions then its testidentifier will be same. I am putting all questions in collection . then I am iterating Collection & updating corresponding record in db using patch and lookup.  This code is not giving error & also not doing anything. Below is the code & urgent help will be appreciated.

 

Clear(QuestCollect);


Collect(
QuestCollect,
ForAll(
Gallery_1.AllItems,
{
Answer: txtAnswer.Text,
QuestionID: lblQuestionID.Text,
TestIdentifier: lblTestIdentifier.Text,
Comments: txtComments_ExternalCor.Text
}
)
);


ForAll(
QuestCollect,
Patch(
'Test QuestionSet',
LookUp(
'Test QuestionSet',
QuestionID = QuestCollect[@QuestionID] && TestIdentifier = QuestCollect[@TestIdentifier]
),
{Answer: QuestCollect[@Answer]},
{Comments: QuestCollect[@Comments]}
)
);

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    156,454 Most Valuable Professional on at

    Hi @Anonymous ,

    I cannot see your data structure, but I have coded the below as I would from a collection with plain Text values.

    You might try this.

    ClearCollect(
     QuestCollect,
     ForAll(
     Gallery_1.AllItems,
     {
     Answer: txtAnswer.Text,
     QuestionID: lblQuestionID.Text,
     TestIdentifier: lblTestIdentifier.Text,
     Comments: txtComments_ExternalCor.Text
     }
     )
    );
    
    ForAll(
     QuestCollect,
     Patch(
     'Test QuestionSet',
     LookUp(
     'Test QuestionSet',
     QuestionID = QuestCollect.QuestionID && 
     TestIdentifier = QuestCollect.TestIdentifier
     ),
     {
     Answer: QuestCollect.Answer,
     Comments: QuestCollect.Comments
     }
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks for your reply. This code is giving error "Invalid Argument Type" & is not working.

  • WarrenBelz Profile Picture
    156,454 Most Valuable Professional on at

    What is giving the error?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Here its giving error at (=)

     QuestionID = QuestCollect.QuestionID

    I think @ is the proper syntax to get value from a collection field. My code runs without syntax error but it comes out from loop very quickly. I think its not executing the complete for each loop.  I have already validated collection, It contains proper records.

     

  • WarrenBelz Profile Picture
    156,454 Most Valuable Professional on at

    OK @Anonymous ,

    This may be something in Regional syntax as .xxx works for me - you need to put them back.

    Without seeing your code, there are two things I would initially test.

    1. Have a look at the Collection QuestCollect and see if they are the records you were expecting.
    2. Look at the fields in this QuestionID and TestIdentifier and ensure they match the relevant fields in 'Test QuestionSet'

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 214 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 185

Last 30 days Overall leaderboard