Limit and Archive off more than 3 Entries per Unique ID

Occasional Contributor

I have a sharepoint list that is tracking locations as we scan objects. I have a history tab and to ensure thte tablet doesnt slow to a crawl or crash I'd like to limit the entries per unique ID to 3 per and send the rest to archive list i have set up.

 

For examplete: Item 1 is scanned 5 times but i only want the most recent 3 scans to show and the archive list to show 2 entries.

6 Replies
*Bump* Is there no one that knows how to limit Sharepoint entries?

@jamescosten 

 

You could create a PowerAutomate flow that does the following:

 

  • If a new Item for a UniqueID is created,
  • Get all other Items for that ID
  • If there are more than three
  • Get the oldest one of these Items
  • Move that item to another list

 

But the requirements seem wierd to me, what exactly are you trying to accomplish with that setup?

Couldn't you just enable versioning on the list and then just update the same item with the unique ID every time you scan a new item?
Or group the list view by the unique ID?


I have a list of 243 unique Items. Each one of these is assigned a location, when it is scanned again it records the new location, but keeps a history of the last location. With 243 items each being scanned multple times a week my list will exceed the limit. Not to mention the issue with the app trying to pull through a large data set. If i could limit it to 3 entries per ID it will prevent the aforementioned issues. I know i can limit the app pulling through too much data, so just need my sharepoint list from exceeding the entry limit.
OK,

but why can't you just keep only 243 items in the list and update every item if the location changes instead of creating a new item?

Then you can access the history of every item through the version history.
To be fair i have only just learnt about the version history so thats fine, however in my app how do i show this? Currently it shows the history by pulling through the last 3 entries, sorted by ID. I cant see any options to show Version history in a data card or gallery

@jamescosten 

It is a little bit more complex in Powerapps to get the version history from SharePoint.

You don't get the version history directly from your datasource, so you need to create a PowerAutomate Flow that fetches the history data for a given item and then dispays it.

The idea is that you have a button in your gallery that opens a new screen.

In the "On visible" Method of that screen you call a PowerAutomate Flow and pass the SharePoint Item ID.

The Flow uses the  "Send an HTTP request to SharePoint" Method to get the Url

https://<tenant>.sharepoint.com/sites/<SITE>/_api/web/lists/GetByTitle('<LISTNAME>')/items(<ID>)/Versions

 Now you have the versioning data and need to do some formatting to pass it back to PowerApps
In PowerApps you collect the data into a new collection and display that data in a gallery on the new screen.

So with screenshots:

First make sure that you have "Parse Json" function turned on in  "Upcoming Features"
features.png


Then create a new flow in your powerapp and call it "ItemVersionHistory"
flow1.png
Use this uri

_api/lists/GetByTitle('<Listname>')/items(<itemID>)/versions


Use this formular in the response-action

string(outputs('Send_an_HTTP_request_to_SharePoint')?['body']['value'])


Then, in powerapps, in the "OnVisible" property of the item details screen enter this

ClearCollect(
    versions,
    ForAll(
        Table(ParseJSON(ItemVersionHistory.Run(BrowseGallery1.Selected.ID).result)),
        {
            Version: Text(Value.VersionLabel),
            Editor: Text(Value.Editor.LookupValue),
            MyField1: Text(Value.MyField),
            MyField2: Text(Value.MyField)
        }
    )
)

You get a new collection "versions" containing all item versions.
If you have custom fields in your SharePoint list (i think you have at least a custom location column) you can get the values for these fields on the time of the version like i got them in Line 8&9

Add a new gallery to your details screen and display the versions there.