Occasionally, you’d probably want to know the time stamp of the last successful run of your power automate flow. For example, you might be working on the data synchronization, and you might need to track those timestamps somehow.
Which is a bit of a problem, it seems. You might try following Linn’s blog here: https://linnzawwin.blogspot.com/2020/08/get-flow-run-by-using-dynamics-365cds.html
But I thought I’d share another option, too.
We won’t be using custom connectors, you won’t be creating new tables… but we will be using environment variables in a little fashioned way. How come it’s old fashioned if environment variables are quite new? You’ll see.
First, let’s create a solution and add new environment variable to the solution:
Make sure “current value” has been added, too, since we won’t be working with the default value.
Now let’s create an instant flow to set environment variable value:
(Here is the expression: first(outputs(‘Get_Environment_Variable’)?[‘body/value’])[‘environmentvariabledefinitionid’]
And the expression here is: first(outputs(‘Get_Current_Value’)?[‘body/value’])[‘environmentvariablevalueid’]
The flow above is going to set environment variable “current value”, and we can call it from any other flow.
Now we need a similar flow to read environment value. Why would we use a flow for that instead of using env variable directly in the flow? That’s because those values would be cached otherwise, so we may have to restart the flow to read updated values. And, when reading those values directly from Dataverse, we don’t have such limitation.
It’s a very similar flow, which is using very similar actions:
The main difference is, likely, that it’s returning a value. Here is the expression for that last step:
Now we can use those flows above in any other flow to track the timestamp (or other ad-hoc values if needed). For example, here is how it could be done:
Below is how Parse JSON and Compose look like:
At the beginning of the flow, I’m reading last time stamp from the environment variable current value. At the end of the flow, I update that value. You can see how it’s getting updated on the screenshot below: