Forum Discussion
Limit and Archive off more than 3 Entries per Unique ID
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?
- SvenSieverdingDec 01, 2022Bronze ContributorOK,
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.- jamescostenDec 01, 2022Brass ContributorTo 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
- SvenSieverdingDec 01, 2022Bronze Contributor
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"
Then create a new flow in your powerapp and call it "ItemVersionHistory"
Use this uri_api/lists/GetByTitle('<Listname>')/items(<itemID>)/versions
Use this formular in the response-actionstring(outputs('Send_an_HTTP_request_to_SharePoint')?['body']['value'])
Then, in powerapps, in the "OnVisible" property of the item details screen enter thisClearCollect( 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.