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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Delete Specific Item f...
Power Apps
Unanswered

Delete Specific Item from Collection

(0) ShareShare
ReportReport
Posted on by 5,325 Super User 2025 Season 2
I have a mobile app that can be used 'Offline'.

I have two collections (Project number and related data, and images) that are saved to the
device, with a 'SavetoDevice' command, when there is no cellular service.

Those two collection a re-populated, with 'Load' commands once the device is back
in cellular service range.

I have two galleries, on different screens, in my app on which the project data, and associated
images from the two collections are viewable.

In the Project data Gallery I have a submit button that includes a Remove(Collection,ThisItem)
command that deletes the project from the project Collection (and gallery).

I also want to be able to concurrently delete the associated project image(s) from the Image
Collection when the Project data is deleted from the Project Collection - using a command in the
same submit button.

How can this be achieved?  
Categories:
I have the same question (0)
  • Verified answer
    Pstork1 Profile Picture
    68,707 Most Valuable Professional on at
    Use the field in the project data that is used to relate the image data to it and use a RemoveIf() on the image collection.  something like
     
    RemoveIf(imagecollection, relatedimagefield = thisitem.field)
  • Phineas Profile Picture
    5,325 Super User 2025 Season 2 on at
    I believe I misspoke.

    This is what I now have in the Submit button of the Project data gallery.

    The second line is what you recommended.
     
    Remove(colPendingStormWorkData,ThisItem);
     
    RemoveIf(colPendingStormWorkImages,ThisItem.colPending_Title = SWJPU_Gallery_Work_Order_Number_Fld.Text);

    I am running a CountRows on colPendingStormWorkData and Images. On my phone the red squared totals show 1 (data), 2 (images).
    When I click the submit button the one project item and the two images are added to the dataset in the list and library, are deleted from the two collections, and the red squared totals show '0' for both.

    However, the items are not being deleted from the device storage, and when I close the app and open it again the project item and the two images are loaded back into the Collections.

    I am using the following in a submit button at data collection (when the device is in 'Offline' mode) to save the project data and image(s) to the device.
     
    If(JS_Job_Type_Dropdown.Selected.Value = "Storm Work",
    SaveData(colPendingStormWorkData,"SavedOfflineStormWorkProjectData"));
     
    If(JS_Job_Type_Dropdown.Selected.Value = "Storm Work",
    SaveData(colPendingStormWorkImages,"SavedOfflineStormWorkProjectImages"));


    I am using the following at App OnStart to Load the data from the device back to the collections.
     
    LoadData(colPendingStormWorkData,"SavedOfflineStormWorkProjectData");
    LoadData(colPendingStormWorkImages,"SavedOfflineStormWorkProjectImages");

    How do I ensure the Project item and images that are being deleted from the collections are also cleared from the device storage,
    and are not reloaded to the Collections when the app is opened again?

  • Pstork1 Profile Picture
    68,707 Most Valuable Professional on at
    Two things to point out.
     
    1) The RemoveIf needs to come before the Remove.  The Remove will delete the item referenced as ThisItem, so you need to use that reference in the RemoveIf before removing it.
     
    2) There needs to be some value specifically in the image that ties it to a specific Job. Based on your current code it looks like the only thing is Job Type. But I suspect there will be multiple Jobs with the same Job Type. The connection between Job and Image needs to be unique or the RemoveIf won't work right.
  • Phineas Profile Picture
    5,325 Super User 2025 Season 2 on at
    I've reordered the formulas to the following.

    The 'Title' is the project work order number, which appears in the 'Title' columns of both the List and Library and are unique.
     
    RemoveIf(colPendingStormWorkImages,ThisItem.colPending_Title = SWJPU_Gallery_Work_Order_Number_Fld.Text);
     
    Remove(colPendingStormWorkData,ThisItem);

    I get the same result; the item(s) are added to the List/Library. A collect of the Collections shows the items have been
    removed from the Collections in the app.

    However, when I close the app and come back in the items are added back to the Collections and Gallery

    There is no command that is deleting / removing a specific item upon upload to SharePoint from the device storage.
    I have the following at the end of the submit button, in an attempt to try to clear the item(s) from the device storage,
    but it is not working.
     
    ClearData("SavedOfflineStormWorkProjectData");
     
    ClearData("SavedOfflineStormWorkProjectImages");

    As it pertains to the above, the 'OnStart' is using the following to retrieve the data from the device storage.
     
    LoadData(colPendingStormWorkData,"SavedOfflineStormWorkProjectData");
     
    LoadData(colPendingStormWorkImages,"SavedOfflineStormWorkProjectImages");
  • Pstork1 Profile Picture
    68,707 Most Valuable Professional on at
    Are you doing a SaveData after you remove and removeif the collections? if not then the LoadData when you restart would load the collection state from before the remove and removeif were processed.  I also normally keep a collection of deleted items so I can delete them from the sharePoint list when I sync the offline data back. Syncing back a collection that no longer contains the deleted items will not delete them from SharePoint.
  • Phineas Profile Picture
    5,325 Super User 2025 Season 2 on at
    I am not, yet.

    Here is what I have at the end of the submit button, in an attempt to remove the item from the collection and the device.

    Can you please articulate how you would modify the following to achieve my goal?

    Also, the below ForAll is associated with the screen and gallery where the images are located. It is unclear to me where I have the RemoveIf formula written correctly.
    colPendingInstallImages is the collection where the images from the device storage are housed at 'OnStart'. The IJPU_Gallery is where the associted data is housed on the opposite screen. coPending_Title and IJPU_Gallery_Work_Order_Number_Fld.Text are referencing the same unique Work Order Number.
     
    If(JPU_Job_Type_Dropdown.Selected.Value = "Install",
        ForAll(
            JIPU_Images_Gallery.AllItems,
        UploadJobImageFlow.Run(JIPU_Location_Fld.Text,
        JIPU_Image_Description_Fld.Text,
        JIPU_Company_Name_Fld.Text,
        JIPU_Work_Order_No_Fld.Text,
        JIPU_Job_Type_Fld.Text,
        JIPU_Work_Date_Fld.Text,
        {
            file: {
                contentBytes: JIPU_Image.Image,
                name:  JIPU_Location_Fld.Text & " - " &  JIPU_Job_Type_Fld.Text &" - "& JIPU_Image_Description_Fld.Text & " - " & JIPU_Company_Name_Fld.Text &" - "& JIPU_Work_Order_No_Fld.Text &" - "&  JIPU_Work_Date_Fld.Text & ".jpg"
            }
        }
    )));
     
    Reset(JPU_Job_Type_Dropdown);
    Reset(JPU_Location_Dropdown);
    Reset(JPU_Work_Order_Number_Dropdown);
     
    Set(varViewPendingUpload,false);
    Set(varSavetoCollectionEnabled,true);
    Set(varActivityComboBoxReset, false);
    Set(varActivityComboBoxReset, true);
     
    Set(myActivityComboBox, {Value: Blank()});
     
    UpdateContext({varPUResetTripCheckbox: false});
    UpdateContext({varPUResetTripCheckbox: true});
     
    RemoveIf(colPendingInstallImages,ThisItem.colPending_Title = IJPU_Gallery_Work_Order_Number_Fld.Text);
     
    Remove(colPendingInstallData,ThisItem);
     
    Notify("The Install project and images have been successfully saved to SharePoint");
     
    If(IJPU_Job_Gallery.AllItemsCount = 0,
    Navigate(Job_Screen,ScreenTransition.Cover));
  • Verified answer
    Pstork1 Profile Picture
    68,707 Most Valuable Professional on at
    I think you are missing two things. 
     
    1) you need to add two SaveData() lines to the end of that OnSelect.  Otherwise the collections will be rebuilt to the state before the Remove and RemoveIF when you LoadData() next.
     
    SaveData(colPendingStormWorkData,"SavedOfflineStormWorkProjectData");
     
    SaveData(colPendingStormWorkImages,"SavedOfflineStormWorkProjectImages");
     
    2) Removing the items from the local collection will not remove them from the SharePoint online Data Source when you sync info back to SharePoint.  If they existed in SharePoint when you loaded the information originally you need to implement some way to delete them when you sync. I normally do that by keeping a collection of titles for the items I removed from the local collection. Then remove them from SharePoint when I sync online.
  • Phineas Profile Picture
    5,325 Super User 2025 Season 2 on at
    Prior to receiving your latest, I add the following two ClearData
    formulas after the Remove/RemoveIf.

    ClearData("SavedOfflineStormWorkProjectData");
     
    ClearData("SavedOfflineStormWorkProjectImages");
     
     
    Are you recommending that I replace the above with the below?
     
    SaveData(colPendingStormWorkProjectData,"SavedOfflineStormWorkProjectData");
     
     
    SaveData(colPendingStormWorkProjectImages,"SavedOfflineStormWorkProjectImages");
  • Verified answer
    Pstork1 Profile Picture
    68,707 Most Valuable Professional on at
    Yes, because those will clear out the saved local collections entirely. If you exit the app after running that, before you do a SaveData elsewhere the LoadData's will fail in the OnStart.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard