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 / ForAll -> IF Statement...
Power Apps
Answered

ForAll -> IF Statement -> Remove row from sharepoint (Problem)

(0) ShareShare
ReportReport
Posted on by 40

Hello to all!

 

I'm trying to build an action that defines what to do to a sharepoint list in function of a column (Ação) that I have in a collection (collectionA). 

 

In my CollectionA, I've a column (Ação) with three types of string records:

"Equal"

"Add"

"Change"

"Remove"

 

 

ForAll(ColletionA;
If(Ação="Add";
Patch('MaR.OOP';Defaults('MaR.OOP');{Title:ThisRecord.OOP;'0A ID OE':ThisRecord.OE;'AF Valor':ThisRecord.Novo});
 
 If(Ação="Change";
Patch('MaR.OOP';LookUp('8.MaROOP';Concatenate(OOP;OE)=Title&'0A ID OE');{'AF Valor':ThisRecord.Novo});

 If(Ação="Remove";
 Remove('MaR.OOP';LookUp('8.MaROOP';Concatenate(OOP;OE)=Title&'0A ID OE';ID))

Refresh('MaR.OOP');;ClearCollect('8.MaROOP';'MaR.OOP');;

 

 

 

 

At the moment my formula function works well for all except the last one... The Remove Action.

 

I calling the ID to be removed with a lookup (in a ForAll loop) but i cant understand why this lookup if providing me an error... in the action "Change" worked perfectly.. 

 

'MaR.OOP' -  is my sharepoint List

'8.MarOOP' - is the Collection that i'm using to collect the value of 'MaR.OOP'

 

 

Can anyone help me? 

 

thank very much 🙂

Categories:
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Joao_Macau 

    A couple of things:

    Your problem is that ForAll is not a For/Loop.  It is a formula that creates tables based on the information provided.

    The information you are providing is a Record (from the first If) a Record from the second if, and the Remove will return a Table.  So the inner record of your ForAll is mismatched and not valid.

     

    You mentioned two collections, but your formula also uses a "CollectionA".  What is the relevance of that?

     

    You need not create multiple collections of the same information as this can all be achieve with 1 or no collections.

     

    Consider RemoveIf instead of the Remove function as your success in matching a record will be much higher.

    RemoveIf should reference the primary key of the list to delete from - in your case ID.

    Although you can RemoveIf by other criteria, the ID is the most reliable as your list grows in size.

     

    Your ThisRecord references are referencing the wrong values in your current formula.  ThisRecord needs to be used with caution as it references the most recent record in the formula chain.  So for example in your "change" logic, it is referencing the LookUp values, not the record from the table iteration of the ForAll.

     

    Please consider changing your Formula to the following:

    Collect('MaR.OOP';
     ForAll(
     Filter(ColletionA; Ação="Add") As _item;
     {Title: _item.OOP; '0A ID OE': _item.OE; 'AF Valor':_item.Novo}
     )
    );;
    Patch('MaR.OOP',
     ForAll(
     Filter(ColletionA; Ação="Change") As _item;
     {ID: _item.ID; 
     'AF Valor': _item.Novo}
     )
     )
    );; 
    ForAll(
     Filter(ColletionA; Ação="Remove") As _item;
     RemoveIf('MaR.OOP'; ID=_item.ID)
    )

    Also, you do NOT need the costly Refresh on your list that you had in the formula.  The changes you make will be immediately reflected in your app.

     

    The above formula assumes that you have the information you need for your records in the CollectionA collection.  For simplicity of your formula, I would strongly consider making sure that collection has the values you want rather than doing another lookup to another collection to get the same values.

    IF for some reason that is by design, then let me know and we can alter the above to fit that.

     

    I hope this is helpful for you.

     

     

  • Joao_Macau Profile Picture
    40 on at

    Thank you so much for the reply!!! It worked

     

    Also you open a new world for me! 

    thank very much sir!

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

    @Joao_Macau 

    Happy to help!

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 236 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 188 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 130

Last 30 days Overall leaderboard