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 / Performing UpdateIf an...
Power Apps
Answered

Performing UpdateIf and Patch in same Event

(1) ShareShare
ReportReport
Posted on by 32

I have the following calls inside an OnSelect method of a button, I am trying to update a number of records first (old ones which are Active), to Inactive.

I then want to create a number of new records based on the collection I have created from a gallery.

The trouble is when I have just the UpdateIf statement in the event call, the old records update ok.

However, if I add the final part (ForAll - new record creation), the update doesn't fire for the old records?

Any ideas?

 

Clear(clItems);
ForAll(
glrQuestions.AllItems,
Collect(
clItems,
{
Answer: txtAnwer.Text
}
)
);
UpdateIf(
Answers,
Status = 'Status (Answers)'.Active,
{
statecode: 'Status (Answers)'.Inactive,
statuscode: 'Status Reason (Answers)'.Inactive
}
);
ForAll(
clItems,
Patch(
Answers,
Defaults(Answers),
{
new_answer: clItems[@Answer]
}
)
);

Categories:
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hi @jimbo_00 

     

    Can you try to update your expression to:
     
    Clear(clItems);
    ForAll(
    glrQuestions.AllItems,
    Collect(
    clItems,
    {
    Answer: txtAnwer.Text
    }
    )
    );
    UpdateIf(
    Answers,
    Status = 'Status (Answers)'.Active,
    {
    statecode: 'Status (Answers)'.Inactive,
    statuscode: 'Status Reason (Answers)'.Inactive
    }
    );
    ForAll(
    clItems,
    Patch(
    Answers,
    Defaults(Answers),
    {
    new_answer: Answer
    }
    )
    );
     
    Hope this Helps!

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
  • poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    @jimbo_00 

     

    Where you say

     

    new_answer: clItems[@Answer]

     

    You have ForAll, so the scope is already inside clitems.

     

    Therefore, you should be able to say just:

     

    new_answer: Answer

     

    Check if this helps.

  • Jim Tait Profile Picture
    32 on at

    Tried this and doesn't work as need to reference 'clItems' otherwise I see blanks in the data.

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hey @jimbo_00 

     

    Do you have a column with Name Answer in the Answers list? If so, then you need to clitems[@].

    Can you try to update the configuration to:

    1) Create a New button and on the OnSelect property of the new button use the expression:
    ForAll(
    clItems,
    Patch(
    Answers,
    Defaults(Answers),
    {
    new_answer: clItems[@Answer]
    }
    )
    );

    Mark this second button as invisible.

    2) Update the expression on first button to:
    Clear(clItems);
    ForAll(
    glrQuestions.AllItems,
    Collect(
    clItems,
    {
    Answer: txtAnwer.Text
    }
    )
    );
    UpdateIf(
    Answers,
    Status = 'Status (Answers)'.Active,
    {
    statecode: 'Status (Answers)'.Inactive,
    statuscode: 'Status Reason (Answers)'.Inactive
    }
    ); Select(Button2)

    Also, if this doesn't work, please check the App Checker and confirm if you are seeing any errors.

     

    Hope this Helps!

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    HI @jimbo_00 ,

    Could you please share a bit more about your issue?

    Do you mean that the UpdateIf formula would not work when you add the final ForAll function?

     

    Based on the formula you provided, I could not find any syntax issue with it. As an alternative solution, please consider modify your formula as below:

    Clear(clItems);
    ForAll(
     glrQuestions.AllItems,
     Collect(
     clItems,
     {
     Answer: txtAnwer.Text
     }
     )
    );
    ForAll( // Put the ForAll function before the UpdateIf function
     clItems,
     Patch(
     Answers,
     Defaults(Answers),
     {
     new_answer: clItems[@Answer]
     }
     )
    );
    UpdateIf(
     Answers,
     Status = 'Status (Answers)'.Active,
     {
     statecode: 'Status (Answers)'.Inactive,
     statuscode: 'Status Reason (Answers)'.Inactive
     }
    );

     

    Please consider take a try with above solution, check if the issue is solved.

     

    Best regards,

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 194 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 150

Last 30 days Overall leaderboard