Understanding “Record Count” and “NULL” condition check expression in “List Records” step of Common data service action in Microsoft flows

Be it “Citizen developers” or long time technical consultants in Dynamics, Microsoft Flows haven’t ceased to impress all. It’s liked by developers and customers alike and many a times have a deciding factor when choosing Dynamics 365 as the desired CRM platform over its competitors.

And if you have used Microsoft flows for Common data service, you must have used the “List records” step as well. And there are many cases where you need to perform an action based on whether the list returned any records or not. While this just seems too easy, surprisingly if you are not aware of the syntax, it may take some time for you to make it work.

The syntax for it is – length(body(‘<your list record action name>’)?[‘value’])

Well, the length function here is pretty obvious. However the trick here is to understand on how to get the array of items returned. If you inspect the results of list record step, you will find that the results are returned in an array called ‘value’.  You can check the length to be greater than zero or not and then take appropriate steps.

image

But wait. What is the “?” operator used for. And believe me, I keep on getting this question multiple times. To put in simple terms, it does check for not null condition and then evaluates the next step, just like you do in your code so that you don’t get “Object reference” error in your code.

Let’s take an example here. Say you want to get the GUID of the first record returned by “List Records” action. To test this in my flow, I create a very simple flow with “List records” step and post that I am initializing a variable with the GUID of the first record.

image

Observe carefully here. I have not used “?” operator here. Now this flow runs successfully when List records steps return data. However when there are no records returned in “List Record” step, then we get the below error.

image

I go ahead and update the expression now as shown in the below screenshot. Notice I have used the “?” operator here.

image

All set and done and when I run the flow this time, the flow runs successfully. As expected the value of the variable “X” is empty as there are no records returned.

image

Small stuff but end up saving some time.

Hope this helps!

Cheers!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Multiselect picklist for Dynamics 365 (http://www.xrmforyou.com/multi-select-picklist.html)

Advertisements

Why is my calculated field not showing in rollup field definition?

And I had the same from my customer development team. The first thing I did was go to “Rollup Field” documentation in Microsoft Docs and sent to cross check the below points. After creating calculated fields over the years, I thought this has to be something related to configuration.

image

(Pic courtesy: Microsoft Docs)

Well, if you are wondering why your rollup field is not showing, most likely it is due to first of the two conditions mentioned.

Coming back to our scenario, client confirmed that they have not violated these scenarios. It was bit surprising as I had configured calculated fields in roll-up definition multiple times. So I had no other option but to open their calculated field definition.

And there I found it. What I realized is that beginners starting with roll-up field may make the same mistake too. Although their calculated field was not using other calculated field but they were using a field from parent entity in their calculated field definition.

If I take the second statement –A rollup can’t reference a calculated field that uses another calculated field, even if all the fields of the other calculated field are on the current entity”, one of the implicit perception from this would be – A rollup field can’t reference a calculated field that uses field of the parent entity in it’s definition”.

For experienced consultants, this may come in naturally. But what I realized from my experience is for beginners in Dynamics, they may tend to miss this point. The developer here just spent couple of hours trying to figure this out Smile

Hope this helps!

Cheers!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Multiselect picklist for Dynamics 365 (http://www.xrmforyou.com/multi-select-picklist.html)