You can easily retrieve the unique identifier of a record in CDS within flow using the List Records action. But this approach will create an “Apply to each” loop, even if there is only one possible result.
I needed to get the accountid from the Account entity to create a new record in a related table. My list records action looks like this:
Note that “Top Count” is set to 1.
The next step of the flow where the new record is created. You can stop the Apply to Each loop being created by using the “first” function. Example code:
first(body('List_records')?['value'])?['accountid']
Then you can continue to your next action without having to deal with a for each loop. It makes the flow neater and easier to comprehend.
Jim says
Can you show the expression please, I am struggling working out the structure you have used?
Paulie says
It’s written above in the post, but it is:
first(body(‘List_records’)?[‘value’])?[‘accountid’]
antonjuniorche says
Hi, I just want to say that this post is really helpful.
I was tasked to revise an old flow with new requirements and all the “apply to each” paths were really confusing but I could not find alternative to make it simpler, until I found your post and it worked.
thank you for sharing!
Cooky says
Hey Paulie, just used this and found it perfect for my needs, but using the new connector, you need to add the table before it, so your paramter would be
/accounts(first(body(‘List_records’)?[‘value’])?[‘accountid’]) I think
Sam Misemer says
WOW This post has solved an issue I’ve been struggling with for two days now. Thanks for concisely addressing the issue, and thanks to Cooky for updating it for the new Dataverse connector!!
Rachael Boneck says
You can also do this for the old connector
body(‘List_records’)?[‘value’]?[0]?[‘accountid’]
Or this for the new connector
outputs(‘List_records’)?[‘body’]?[‘value’]?[0]?[‘accountid’]