cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SpiritBear
Regular Visitor

Comparing previously entered value on a "Change to List Item" trigger flow?

Hi all,

 

My assumption is this may not be possible, but wanted to ask.

 

I have a SharePoint List that is for a project tracker and it has a "Due Date" column. I have a flow that is set up to monitor the list for new item creation, and if a new item is created and there is a value in the "Due Date" column, it sends out a calendar event to the assigned person to the task. If there is no value assigned to the "Due Date" column, it does not send out an invite. It also saves the event id for the calendar event it create to that item so I can reference it later.

 

What I would like to write is a second flow that is triggered when an existing item is updated and then does the following workflow:

  • If the date is the same as before the item was edited in the Due Date column, or there is still no date in the Due Date column, do not send out an invite.
  • If the date is different than the date that was in the Due Date column, reference the event id and change the event date/time.
  • If the Due Date column was empty before the update, set up a new invite and log that event id to the item.

My main question is, is there a way to see what was in Due Date date field before the change was made, or is that data immediately lost as soon as the item is update in Lists?

 

Thank you kindly!

1 ACCEPTED SOLUTION

Accepted Solutions
tom_riha
Super User II
Super User II

Hello @SpiritBear ,

it depends if you have version history enabled on the SharePoint list. If it's enabled you can access the previous version of an item and take data from there. There's an HTTP request that will return all versions of an item: 

Method: GET
Uri: _api/web/lists/getByTitle('[ListName]')/items([ItemId])/versions

Uri example: _api/web/lists/getByTitle('MyList')/items(1)/versions

The result JSON should be parsed using the 'Parse JSON' action (use the result as the example payload to create the schema automatically). That will give you access to all previous versions. But since you're interested only in the single previous version, you should filter the result to get only that one.

That means 'Filter array' action to filter from the results only the version that's -1 from the current version.

[VersionLabel] <is equal to> concat(add(int([CurrentItemVersion]),-1),'.0')

Notes:
[VersionLabel] contains each version version number
[CurrentItemVersion] is the current version of the item
add(int(.., -1)) will convert the version number into integer and subtract 1 version
concat(.., '.0') will add .0 to the version number as versions in SharePoint have format x.0

Output from this 'Filter array' action will be the previous version of the item with the previous values.

image.png

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

4 REPLIES 4
tom_riha
Super User II
Super User II

Hello @SpiritBear ,

it depends if you have version history enabled on the SharePoint list. If it's enabled you can access the previous version of an item and take data from there. There's an HTTP request that will return all versions of an item: 

Method: GET
Uri: _api/web/lists/getByTitle('[ListName]')/items([ItemId])/versions

Uri example: _api/web/lists/getByTitle('MyList')/items(1)/versions

The result JSON should be parsed using the 'Parse JSON' action (use the result as the example payload to create the schema automatically). That will give you access to all previous versions. But since you're interested only in the single previous version, you should filter the result to get only that one.

That means 'Filter array' action to filter from the results only the version that's -1 from the current version.

[VersionLabel] <is equal to> concat(add(int([CurrentItemVersion]),-1),'.0')

Notes:
[VersionLabel] contains each version version number
[CurrentItemVersion] is the current version of the item
add(int(.., -1)) will convert the version number into integer and subtract 1 version
concat(.., '.0') will add .0 to the version number as versions in SharePoint have format x.0

Output from this 'Filter array' action will be the previous version of the item with the previous values.

image.png

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

SpiritBear
Regular Visitor

Thank you, @tom_riha !

 

That was absolutely the direction I was looking for to get me started. Many thanks.

SpiritBear
Regular Visitor

I have a follow question @tom_riha .

 

So I implemented the code successfully and have gotten it to compare the previous version and send out a revised calendar invite if the "Due Date" field has changed.

 

However, I'm having an error thrown by the Parse by JSON.

 

If the "Due Date" field was blank in the previous version, Parse by JSON is erroring out because it's getting a NULL and expecting a String. Any thoughts? I'm newish to PowerAutomate, so not sure if there is a version of "on error" I could call.

Hello @SpiritBear ,

copy the schema from 'Parse JSON' in a text editor and search for the 'Due Date' entry, it'll look something like:

"DueDate": {
    "type": "string"
}

add the possibility of the null value in the type:

"DueDate": {
    "type": ["string","null"]
}

Copy/paste the updated schema back into the 'Parse JSON' action.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Carousel

Sign up for our May 4th event!

May the fourth be with you, join us online!

MSFTBizAppsLaunchEvent

Experience what’s next for Power Virtual Agents

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (87,778)