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 / if statement not execu...
Power Apps
Answered

if statement not executing the true value

(0) ShareShare
ReportReport
Posted on by

Hi community,

i have save button in my app and i want it to save into two separate SPO lists,

NeedToSave and VarStatus are two variables that evaluate whether the user made changes that need to be saved and then save it.

it should save to either one of them or to both based on the varailables evaluated to true.

but only the first part of the formula is working and saving to the VP Weekly Status table, the other part is not saved although the VarStatus variable is true.

when taking the second part of the formula into a separate button (not withon an if statement) it works just fine.

any ideas?

my formula:

 

If(NeedToSave,
 ClearCollect(
 UpdatedItems,
 ItemsGallery.AllItems
 );
 ForAll(UpdatedItems, Patch(
 'VP weekly status',
 LookUp('VP weekly status',ID=UpdatedItems[@ID]),
 {Report_Items:TextInput3.Text},
 {Week:WeekValVP},
 {DataType:{
	 '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
 Value: ItemType,
 ID:ItemsGallery.Selected.ID
	}}
)),
 varStatus,
 ForAll( 
 Gallery2_1.AllItems,
 Patch(AccountsWeeklyStatus,ThisRecord,{Status:{ Value:LblUpdatedStatus_1.Text},'Status Description':TxtStatusDesc.Text}))
)

 

 

 

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    155,242 Most Valuable Professional on at

    Hi @Perez ,

    That is because you have the second Patch as the "else" of the If() statement - try this (note you do not need the odata.type reference any more)

    If(
     NeedToSave,
     With(
     {wItems:ItemsGallery.AllItems},
     ForAll(
     wItems As aPatch, 
     Patch(
     'VP weekly status',
     {ID=aPatch.ID},
     {
     Report_Items:TextInput3.Text,
     Week:aPatch.WeekValVP,
     DataType:
     {
     Value: aPatch.ItemType,
     ID:ItemsGallery.Selected.ID
     } 
     }
     )
     )
     )
    );
    If(
     varStatus,
     ForAll( 
     Gallery2_1.AllItems,
     Patch(
     AccountsWeeklyStatus,
     ThisRecord,
     { 
     Status:{Value:LblUpdatedStatus_1.Text},
     'Status Description':TxtStatusDesc.Text
     }
     )
     )
    )

     

    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.

  • EP-29071004-0 Profile Picture
    on at

    @WarrenBelz , thanks for the quick reply.

    i tried your formula, and it gives set of errors.

    Perez_0-1614856644282.png

    can you please elaborate about the use of the With function and As operator.

    as for my original formula in the UI it looks like it is the true value for the second logical test

    Perez_1-1614856842617.png

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Perez 

    Just chiming in here because I noticed in your formula that you were wasting the output of the ForAll.  ForAll is a function that returns a table - it is too overused as a programming For/Next and the results wasted.  This also impacts performance.

     

    Consider the following formula for what you need:

    If(NeedToSave,
     Patch(
     'VP weekly status'
     ForAll(ItemsGallery.AllItems As _item, 
     LookUp('VP weekly status',ID=UpdatedItems[@ID]),
     {ID: _item.ID,
     Report_Items: _item.TextInput3.Text,
     Week: WeekValVP,
     DataType:{Value: ItemType, ID:ItemsGallery.Selected.ID}
     }
     )
     )
    );
    
    If(varStatus,
     Patch(AccountsWeeklyStatus,
     ForAll(Gallery2_1.AllItems As _item,
     {ID: _item.ID,
     Status: {Value:_item.LblUpdatedStatus_1.Text},
     'Status Description': _item.TxtStatusDesc.Text
     }
     )
     )
    )

     

     

    HOWEVER... @WarrenBelz was spot on, and deserves the solution for this, that you had your second part in the else of the If.  So, this would never work to do both conditions.  It would have only done NeedToSave (if true) or varStatus (if NeedToSave was false and varStatus was true).

     

    I hope this is helpful for you.

  • EP-29071004-0 Profile Picture
    on at

    thanks, it worked!!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 914

#2
11manish Profile Picture

11manish 627

#3
Valantis Profile Picture

Valantis 598

Last 30 days Overall leaderboard