Cracking the JSON of Cloud Flows

Recently I had to do an analysis of a lookup field’s dependencies because it needed to be replaced by a new field looking up to a different table (itself a long story…).

It was all going well, I went into the Maker Portal, I found the table, found the field (sorry – column!), selected it and clicked ‘Show Dependencies’. Wonderful!

Except…

The dependencies list will only show you the cloud flows that use this field column as a trigger – not as a condition or action or anything else outside of the trigger. Which means that you are able to delete the field even if it means a bunch of flow actions will suddenly start failing because the thing doesn’t exist anymore. Where’s the fun in that….nowhere I tell you!

Soooo…what does this mean?

WELL. It basically means you have to search all cloud flows and see if any actions are using that field. Yep. I know. Thankfully there is an automated way to do this – don’t be that person that spends 2 weeks looking through flow actions #aintnobodygottimeforthat. Let JSON Crack do all the work for you! To learn more about JSON Crack in general and other ways to use it click here.

Using JSON Crack

It is super easy. First you need to get JSON from your environment of choice giving you all the (active, if you so wish) cloud flows in the system. You can do this by sticking the below in your browser – don’t forget to update it for your actual environment:

https://environmentname/api/data/v9.0/workflows?$select=clientdata,name&$filter=(category%20eq%205%20and%20statecode%20eq%201)

It will look like this – copy all the text. Ctrl + A, Ctrl + C is your friend.

Get Cracking

In a new tab (or the same tab, whatever makes you happy), go to https://jsoncrack.com/editor and on the left pane, delete what is there and paste the JSON from the API:

You will then see a wonderful long list of all the cloud flows on the right:

Here’s the good bit – you can use the Search Node box on the top right to look for the schema name of your field – this will search the JSON for any mention of this field in any of the flows which will get a green outline and you can press Enter to move to the next flow that mentions it:

You can also click on a flow to copy the details of it (e.g. name, id) and then open that flow in the Maker portal to see exactly where your field is used and make the necessary changes.

You can then repeat this process to ensure no more mentions of the field exist and then delete it.

Yey for JSON! This is a great tool for visualising JSON data in general so keep it in mind! Big thanks to Christy O’Kane for making me aware of this awesomeness!

Alternatively…

Top Tip by Cris Fernandez:

If you use Chrome, you can view and search this JSON within the browser tab by installing the JSON Formatter extension by Callum Locke. It will format the JSON for you (it will still be a wall of text but a structured wall of text!) and you can then use the browser search (Ctrl + F) to find the field schema. It will be quicker, show you all the places the field pops up, and exactly what has been found as a match in the JSON:

Woop Woop!

Field Deletions and Cloud Flows

We’ve all been there – we have created a field in D365, linked it to a bunch of things like forms and business rules and then we notice the schema has a typo, or we picked the wrong field type. Off we go to delete it and if it is still linked to anything else in the system (i.e. there are other components that use it and therefore depend on its existence), we get an error to tells us that we can’t delete it because the field has dependencies:

Off we go and remove the field from the forms/views/business rules etc it is linked to on the list of dependencies, we check they are all gone from the list and 0 dependencies exist and we DELETE. The system dutifully deletes it and it is history. Wonderful. Except…

Here’s the fun fact: It turns out the system isn’t checking for everything this field is being used in. It will allow you to delete a field even if it is used within a Power Automate flow. When it comes to Power Automate flows the system will only consider a cloud flow a dependency if the field being deleted is included in the triggers of that cloud flow. Otherwise (e.g. if the field is set/used in a step of the flow) the system doesn’t consider it a depency and you can delete the field.

Lets take an example where I have an ‘Employer’ lookup field on the Contact form that allows me to select the Account record of the company this person works for:

For reporting purposes I have a yes/no ‘Contact Records Associated’ flag on the Account form to let me know if an Account does or doesn’t have contacts associated to it:

I create a Power Automate flow on Contact creation (or when the ‘Employer’ field changes on the Contact) that updates the Account ‘Contact Records Associated’ flag to Yes:

If I then look at the dependencies list of the ‘Contact Records Associated’ field, the cloud flow does not appear – only the form the field is on does and I can delete the field even though it is in a cloud flow step:

In contrast – if I create a flow that has the field as a trigger like the below…

Then the flow will appear in the depedencies list (and I can’t delete the field until I have removed it as a trigger):

So what happens to a flow that uses a field within a step when you delete it?

If you open it you will get a misleading message there is an issue with its trigger (but it is not the trigger that is the problem, its the step that is trying to set a deleted field):

Not all hope is lost though, because the flow will show you want it used to do with that field and which field it was starting with ‘item/‘ and then the field schema name:

You won’t be able to save the flow until (in this example) you clear the value that is being set for the deleted field, but once that is done and you refresh, this reference will disappear and you will have a happy flow.

How do you know which flows you need to go and fix if you are deleting a field since the dependencies list won’t tell you? See here for full details!