cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
crirojsab
Helper I
Helper I

Extract the last item from an Archive list

Hello I'm trying to extract the last item from the version history of one list to use it in a Flow and to compare and extract other values. At this point I'm able to get the entire list of items using the next HTTP Request. 

 

 

crirojsab_0-1616450175075.png

However I'm getting the entire pool of items. There is any way to get all the values of the last record entered in history of the list? 

 

Regards. 

Cristian. 

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @crirojsab,

 

As far as I am aware you should also see updates to lookup columns in your version history.

 

I think I misunderstood something. The information we are now collecting is the current version. I guess you mean previous version when you are talking about the last item? So, if the current version is 3.0, you want to collect the lookup value of version 2.0?

 

In that case use this:

 

Versions?$top=2

 

 

And for your outputs expression use this to collect the second item, the previous version:

 

outputs('Send_an_HTTP_request_to_SharePoint')?['body']['d']['results'][1]

 

 

Btw, on a side note. There is an action called get changes for an item or file (properties only). This can also be useful to track which columns have changed.

 

getchangesforitem.png

 

The output of that example action would be something like this:

 

{
  "SinceVersionExisted": true,
  "SinceVersionId": 1024,
  "SinceVersionLabel": "2.0",
  "UntilVersionIsCurrent": false,
  "UntilVersionId": 1536,
  "UntilVersionLabel": "3.0",
  "ColumnHasChanged": {
    "ID": false,
    "Title": true,
    "TestLookup": false,
    "Modified": true,
    "Created": false,
    "Author": false,
    "Editor": false,
    "ComplianceAssetId": false
  }
}

 

View solution in original post

6 REPLIES 6
Expiscornovus
Super User
Super User

Hi @crirojsab,

 

Can you add this to the end of your URI field?

?$top=1

 

That should give you the last version of your list item.

top1_getversions.png

Hi Exopircornovus:

 

Brilliant. Thanks for what It seems to be a very simple solution. Leaving the office now so I'll be checking this tomorrow and I'll be letting you know at first hour of the morning. 

 

Regards

crirojsb

Hi Expiscornovus:

 

Just arrived home and believed that I had enough time to think in the traffic jam your answer and just want to be sure. . This expression is going to return the most recent or newest entry in the version history of the list? 

 

That's because I have the feeling that is going to return the record that is in the first place of the list and not sure if is the oldest one (that is not the idea) or the Newest record that is what I'm seeking and what I need.

 

Thanks for your time

 

 

 

Expiscornovus
Super User
Super User

Hi @crirojsab,

 

As far as I am aware Microsoft will retrieve the versions in descending order. So, the first item should always be the latest.

 

If that doesn't work let me know. Otherwise we can always add a sort descending.

$top=1&$orderby=VersionLabel desc

 

Hi @Expiscornovus 

 

Not sure if this is working. Just add your first suggestion. However need to extract the information from columns that at the end  are lookup fields. 

 

Once finish the HTTP Request do a compose just to extract the 'd' Results :

 

body('Send_an_HTTP_request_to_SharePoint_to_get_version_history')['d']['results'] then Parse the Otuput and  append the old information in a variable to just get the portion that in need. This is the Output"

 

{
  "__metadata": {
    "type""SP.FieldLookupValue"
  },
  "LookupId"25,
  "LookupValue""IT"
}
 
And at the end I just send an email to validate the results but as you can see above the Lookup value is "IT" and the old value should be another one. Below an extraction of the email to get clarity:
-----------------------------------------------------------
Responsable new value: IT

Responsable old value:{"__metadata":{"type":"SP.FieldLookupValue"},"LookupId":25,"LookupValue":"IT"}
-------------------------------------------------
After all this wondering if the Lookup Fields are also stored in the versions history or not? Can you please provide a light here? 
Thanks for your help 
 
 

 

 

 

 

 

 

 

Expiscornovus
Super User
Super User

Hi @crirojsab,

 

As far as I am aware you should also see updates to lookup columns in your version history.

 

I think I misunderstood something. The information we are now collecting is the current version. I guess you mean previous version when you are talking about the last item? So, if the current version is 3.0, you want to collect the lookup value of version 2.0?

 

In that case use this:

 

Versions?$top=2

 

 

And for your outputs expression use this to collect the second item, the previous version:

 

outputs('Send_an_HTTP_request_to_SharePoint')?['body']['d']['results'][1]

 

 

Btw, on a side note. There is an action called get changes for an item or file (properties only). This can also be useful to track which columns have changed.

 

getchangesforitem.png

 

The output of that example action would be something like this:

 

{
  "SinceVersionExisted": true,
  "SinceVersionId": 1024,
  "SinceVersionLabel": "2.0",
  "UntilVersionIsCurrent": false,
  "UntilVersionId": 1536,
  "UntilVersionLabel": "3.0",
  "ColumnHasChanged": {
    "ID": false,
    "Title": true,
    "TestLookup": false,
    "Modified": true,
    "Created": false,
    "Author": false,
    "Editor": false,
    "ComplianceAssetId": false
  }
}

 

View solution in original post

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Users online (1,897)