man is trying to roll a large rock uphill
Common Data Service, Flow, Uncategorized

How to get it right: “List records” just-first-record lookup value expression for CDS current connector

Sometimes I use my own blog to find some information which I am keeping forgetting.

I am always forgetting how to do THIS so I keep it here.

Problem: from the list of items retrieved via List records action for CDS current connector i would like to pick up the first item and get the value of its lookup field.

In my case I retrieve Work Orders and I am looking for the OOB Service Account field (msdyn_serviceaccount).

Unfortunately, the result of the action in the All Runs history looks like this.

Result of the List records action for WOs

Which is extremely useful! NOT

I added another action for the debugging purpose:

Use Compose to inspect Output from WO retrieve action

And I am using Compose here to inspect the Output from Retrieve WOs action.

Compose for Output from WOs retrieve history
"@odata.context": "$metadata#msdyn_workorders(msdyn_name,msdyn_workorderid,_msdyn_serviceaccount_value,msdyn_serviceaccount,msdyn_serviceaccount())",
"value": [
"@odata.type": "#Microsoft.Dynamics.CRM.msdyn_workorder",
"": "",
"@odata.etag": "W/\"941825332\"",
"@odata.editLink": "msdyn_workorders(368b9357-b743-e911-a978-000d3ae0bc37)",
"msdyn_name": "WO-1106064",
"msdyn_workorderid@odata.type": "#Guid",
"msdyn_workorderid": "368b9357-b743-e911-a978-000d3ae0bc37",
"_msdyn_serviceaccount_value@odata.type": "#Guid",
"_msdyn_serviceaccount_value": "5b8c464c-a743-e911-a978-000d3ae0f2e2",
"msdyn_serviceaccount@odata.associationLink": "$ref",
"msdyn_serviceaccount@odata.navigationLink": ""
"@odata.type": "#Microsoft.Dynamics.CRM.msdyn_workorder",
"": "",
"@odata.etag": "W/\"941825383\"",
"@odata.editLink": "msdyn_workorders(318f4f3a-b443-e911-a972-000d3ae0f413)",
"msdyn_name": "WO-1106061",
"msdyn_workorderid@odata.type": "#Guid",
"msdyn_workorderid": "318f4f3a-b443-e911-a972-000d3ae0f413",
"_msdyn_serviceaccount_value@odata.type": "#Guid",
"_msdyn_serviceaccount_value": "3a3c2a89-c9e6-e711-8138-e0071b67ecd1",
"msdyn_serviceaccount@odata.associationLink": "$ref",
"msdyn_serviceaccount@odata.navigationLink": ""

It’s a fun expression time! We have to refer to the action “Retrieve WOs” output body first.


And all the retrieved items will be inside “value”: []

It’s going to be the array of items:


And we pick up the first one:


And then it’s “msdyn_serviceaccount_value” . Watch out the value bit.


It’s kind of silly that I still struggle with it. I found a very good post here:

which describes exactly the same expression and I managed to make mistakes while copying it then modifying. Probably because of the combination of [] and ().

Now I have the place in my blog where I keep it permanently. No more struggle.

2 thoughts on “How to get it right: “List records” just-first-record lookup value expression for CDS current connector”

  1. Hi Olena, nice article. 🙂

    Am just wondering why you wouldn’t use the ‘Top Count’ field in the list records action? Set that value to be 1, and it will only return 1 result anyway.

    You can then use the ‘order By’ field to set the order of results returned, to get the oldest, newset, largest, smallest etc if you need specifically to choose the most recent record created etc.


    1. Hi Matt,
      Thank you for your comment.
      I do use top 1 )) You still have to deal with the list with just one item in the JSON result.
      Something like : [
      “Items”: “test”
      Which automatically make it use Apply to Each to access the item properties which is annoying as hell.
      In my old Flows I returned one item them used Apply To Each and didn’t bother. But it looks much cleaner this way. This is how we would do it in the code for RetrieveMultiple. We would retrieve something we know is the only item them take [0] form the list.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s