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

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Trigger: When an objec...
Power Automate
Unanswered

Trigger: When an object is deleted

(0) ShareShare
ReportReport
Posted on by 8

When I use "when an item is deleted" as a trigger, the following step "get item" doesn't work. Any general suggestions?

 

Categories:
I have the same question (0)
  • Craig Stewart ABZ Profile Picture
    959 Super User 2024 Season 1 on at
    Re: Trigger: When an object is deleted

    What is it you want to do? You can't get the item, because it's been deleted.

     

     

    https://powerusers.microsoft.com/t5/I-Found-A-Bug/When-a-file-is-deleted-SharePoint-action-not-retrieving-all-file/m-p/319942/highlight/true#M4759

  • Louise_Brandt Profile Picture
    8 on at
    Re: Trigger: When an object is deleted

    You got a point there.. 😂 Thanks!

  • Verified answer
    eliotcole Profile Picture
    4,363 Moderator on at
    Re: Trigger: When an object is deleted

    Hi, @Louise_Brandt, like @CraigStewart said you can't do much ... out of the box!

     

    I'm assuming (from your wording) that you're speaking about list items, not files.

     

    This is the information that is provided when this trigger fires:

    {
    	"ID": 8,
    	"Name": "Testing again",
    	"FileNameWithExtension": "Testing again",
    	"DeletedByUserName": "Eliot Cole",
    	"TimeDeleted": "2022-06-02T16:59:11Z",
    	"IsFolder": false
    }

     

    You can find it in the Recycle Bin of your site by performing this call using the Send an HTTP request to SharePoint action:

    HTTP GET item from Recycle Bin.jpg
    _api/web/recyclebin?$filter=DirName eq 'sites/helpdesk/Lists/helpdesk' and startswith(LeafName, '@{triggerOutputs()?['body/ID']}_')

    What I have done with that URI there is ensure that I only get one result from the search, explained in the below spoiler. Also, that is there so that you can just paste it straight in to your 'Uri' field.

    Spoiler (Highlight to read)

    From the left to the right:

    1. Endpoint - Everything before the first '?' is the 'API Endpoint' that you want to call.
      In this case it's the '_api/web/recyclebin' endpoint.

      If you called this without the '?' and the rest, it would retrieve all the items in the Recycle Bin. You could use a filter action in the flow, but why bother if you can do it here.

    2. Filter - This does filter actions on two columns in the Recycle Bin items:
      1. Checks that the 'DirName' is equal to (eq) "sites/helpdesk/Lists/helpdesk".
        This is identifying the list that the deleted item came from.
      2. Using 'startswith()' it checks that the 'LeafName' column starts with the ID number of the deleted item, with an underscore directly afterwards.
        This is identifying the precise item from the list that 'DirName' has picked out, further more that underscore stops it returning IDs of "60", "67" or "600"!
    From the left to the right: Endpoint - Everything before the first '?' is the 'API Endpoint' that you want to call.In this case it's the '_api/web/recyclebin' endpoint.If you called this without the '?' and the rest, it would retrieve all the items in the Recycle Bin. You could use a filter action in the flow, but why bother if you can do it here. Filter - This does filter actions on two columns in the Recycle Bin items: Checks that the 'DirName' is equal to (eq) "sites/helpdesk/Lists/helpdesk".This is identifying the list that the deleted item came from. Using 'startswith()' it checks that the 'LeafName' column starts with the ID number of the deleted item, with an underscore directly afterwards.This is identifying the precise item from the list that 'DirName' has picked out, further more that underscore stops it returning IDs of "60", "67" or "600"!

    To retrieve anything from that single result you would use this expression in any following action:

    body('HTTP_GET_item_from_Recycle_Bin')?['d']?['results'][0]?['Id']

    As you can see I used that [0] to select the first item in the array of 1 item. With that I selected the 'Id' of the Recycle Bin item ... that could be useful!

     

    Now that you have the Recycle Bin item I'll discuss an easy option that you can use to get the data back, and process it further.

     

    Options For Getting Information on Deleted List Items

    This is a relatively straightforward process, which I'll try to provide images for, but I hope it does not really need them. This process assumes your list uses the nice, modern, 'new' list experience, by the way.

     

    Make a 'deleted' Column

    1. Go to the list
    2. Scroll to the right, and select '+ Add column'
    3. When it drops down, select 'Choice'
    4. In the options:
      1. Name it 'deleted' (no quotations)
      2. Set only two choices:
        1. deleted
        2. alive
      3. Ensure that 'Can add values manually' is unchecked
      4. Ensure that 'Use calculated value' is unchecked
      5. Set the 'Default value:' to "alive"
      6. Inside 'More options' ensure that 'Add to all Content Types' is set to 'Yes' and the other options are set to 'No'
      7. Tap 'Save'
    Create a column.jpg

     

     

    Hide The 'deleted' Column

    You can essentially boil down the step-by-step guide in the spoiler to:

    1. Hide the column
    2. Remove it from default view(s)
    3. Add a new view purely for 'deleted' items

    If you are experienced with SharePoint you probably know how to handle that.

     

    If not, tap the spoiler below ... Step 2 of this might be unnecessary if you can already see 'Content Types' in the settings.

    Spoiler (Highlight to read)
    1. Go to the list settings (cog at the top of the screen, select 'List settings')
    2. Enable management of content types:
      1. Go to Advanced settings
      2. Set the first option, 'Allow management of content types?' to "Yes"
      3. Tap 'OK' which takes you back to settings
    3. Hide 'deleted'
      1. Now go to where it says 'Content Types' in the settings, and tap on 'Item'
      2. Look down the list to where you see the 'deleted' Choice column you made and tap on 'deleted'
      3. Select "Hidden (Will not appear in forms)" from the 'Column Settings' options
        Set Content Type.jpg
      4. Tap 'OK' which takes you back to settings.
    4. If you had to perform step 2 you should change it back to "No" now
    5. Remove 'deleted' column from default view:
      1. Head down to the bottom of the settings and tap on the name of the default view which is normally called "AllItems"
      2. In the Columns options deselect "deleted" so it won't display
      3. Scroll a bit further down and set the Filter to 'Show the items when column' "deleted" "is not equal to" "deleted"
        Filter 'deleted' to ''alive''.jpg
      4. Tap 'OK' which takes you back to the main list in that amended default view
    6. Make a 'deleteditems' view:
      1. Tap the view name at the top right and select 'Create new view'
        Create new view.jpg
      2. Name the view "deleteditems" (lower case, no quotes) and make it a list view that is public
        Create view.jpg
      3. That makes a new view which looks familiar so tap the 'deleteditems' view name at the top and select 'Edit current view'
        Edit current view.jpg
      4. Here do the opposite that you did to the previous view:
      5. Ensure the 'deleted' column is displayed
      6. Set the Filter to "deleted" "is equal to" "deleted"
        Filter 'deleted' to ''deleted''.jpg
      7. Tap 'OK'

    Now you have a brand new list view where only the deleted items will show up!

    Go to the list settings (cog at the top of the screen, select 'List settings') Enable management of content types: Go to Advanced settings Set the first option, 'Allow management of content types?' to "Yes" Tap 'OK' which takes you back to settings Hide 'deleted' Now go to where it says 'Content Types' in the settings, and tap on 'Item' Look down the list to where you see the 'deleted' Choice column you made and tap on 'deleted' Select "Hidden (Will not appear in forms)" from the 'Column Settings' options Tap 'OK' which takes you back to settings. If you had to perform step 2 you should change it back to "No" now Remove 'deleted' column from default view: Head down to the bottom of the settings and tap on the name of the default view which is normally called "AllItems" In the Columns options deselect "deleted" so it won't display Scroll a bit further down and set the Filter to 'Show the items when column' "deleted" "is not equal to" "deleted" Tap 'OK' which takes you back to the main list in that amended default view Make a 'deleteditems' view: Tap the view name at the top right and select 'Create new view' Name the view "deleteditems" (lower case, no quotes) and make it a list view that is public That makes a new view which looks familiar so tap the 'deleteditems' view name at the top and select 'Edit current view' Here do the opposite that you did to the previous view: Ensure the 'deleted' column is displayed Set the Filter to "deleted" "is equal to" "deleted" Tap 'OK' Now you have a brand new list view where only the deleted items will show up!

    Now the easy part, the flow!

     

    Edit Your Flow

    All that you need to do now is keep your trigger, but add the HTTP GET item from Recycle Bin I detailed earlier, an HTTP POST to SharePoint to restore that item, and then an Update item to change the item's 'deleted' from from 'alive' to 'deleted'.

    FLOW.jpg
    The Uri field on the HTTP POST to SharePoint to restore is as follows ... you can paste this directly into your 'Uri' field:
    /_api/web/recyclebin('@{body('HTTP_GET_item_from_Recycle_Bin')?['d']?['results'][0]?['Id']}')/restore()

    Suffice to say, this means that nothing will ever be permanently deleted from the list, but deleted items will never show for anyone else.

  • Louise_Brandt Profile Picture
    8 on at
    Re: Trigger: When an object is deleted

    Perfect! That will help!

  • eliotcole Profile Picture
    4,363 Moderator on at
    Re: Trigger: When an object is deleted

    Glad I could 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

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 Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 462 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 456 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard