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.