cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LukasSliuzas
Helper II
Helper II

Remove item from collection if it matches in OnRemoveFile action

Hello,

 

I got a collection of 4 collums that store list ID, Item ID, Name and DataStream. What I am trying to achieve is that I have an attachment control with function OnAddFile:

Collect(colFiles,DataCardValue127.Attachments);
Collect(
    colFinalData,
    {
        Name: Last(DataCardValue127.Attachments).Name,
        DataStream: Image3.Image,
        IDD: CountRows(colFinalData)+1
    }
);

 

Code above adds the attatchments to Sharepoint list without any issues but now the hard part (for me) is to remove the from collection if it was removed. Now I need to figure how to compare Collection Item name and the attachment control name 

3 REPLIES 3
SqtaMorda
Resolver II
Resolver II

I think we recently received possibility to add multiple attachments at once. I think your approach wont work when user add more than one attachment to form attachment card. 

in terms of removing items from collection there is some example:

my first collection,
ClearCollect(col1, {NAME: "Adam", ID: 1},{NAME: "Damian", ID: 2}, {NAME: "Piotr" , ID: 3})
my second collection,
ClearCollect(col2, {NAME: "Adam" , ID: 1},{NAME: "Tomasz", ID: 2}, {NAME: "Krzysztof" , ID: 3})

im removing from first collection items with NAME that exist in second collection

RemoveIf(col1, NAME in col2.NAME)

My solution to add multiple attachments work as I am pushing that collection into PowerAutomate flow. I just need a way to remove the item from collection on clicking X that WASN'T added to sharepoint yet

SqtaMorda
Resolver II
Resolver II

I don't understand why you are creating your file collection this way. Probably it has something with Power Automate and your feature.

my solution is:

 

Everytime i hit OnAddFile i clear and collect list of my datacrad attachments.
OnAddFile = ClearCollect(col1, DataCardValue13.Attachments)

 

On remove file i clear and collect second collection, this way i miss item i just deleted.

Then i remove from my first collection items that are not in my second collection.

OnRemoveFile = ClearCollect(col2, DataCardValue13.Attachments); RemoveIf(col1, !(Name in col2.Name))

I assume that first collection is one you are pushing to PowerAutomate.
Hope it will help you achive your goal, if yes thumb up please!

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (5,239)