Referencing records when using the Common Data Service (current environment) connector

The CDS (current environment) connector is the newer version of the two CDS connectors that are available. It has nice new features such as a Create/Update/Delete trigger, support for Service Principals in solution aware Flows and some smaller features in its different actions. It’s the go-to connector to use in solution aware Flows.

Despite all the improvements, the connector has also taken a step backward when it comes to referencing records. With the original CDS connector, referencing records is as simple as using dynamic content and pointing to a record. In the example illustrated below, all that needs to be done is to choose a project’s id/GUID from a previous action (or in this case the trigger) by using dynamic content. This relates the project task in the Create a new record action to the project that caused the Flow to fire off.

1. Referencing records using the original CDS connector.

With the new CDS (current environment) connector, the results from the previous example will be different. The Flow will fail with an error “Resource not found for the segment xyz”. This happens because the new CDS (current environment) connector expects the referenced attribute values in the form of OData id:
Entity’sNameInPlural(Record’sId/GUID).

2. Flow fails when using dynamic content with the new CDS (current environment) action.

The fix

Typing in an entity name is naturally one approach to solving the problem. Personally I’m not a huge fan of typing in values to actions. It’s also a bit of work to dig out the exact name for an entity, as the naming convention differs between core CE, Field Service and Project Service Automation. While core CE doesn’t have a prefix, Field Service and PSA use msdyn_. Then again Universal Resource Scheduling doesn’t use a prefix, so as you can by now guess, the differences in entity naming conventions in Dynamics 365 for Customer Engagement make it challenging to remember entity names.

To make life simpler, an action including an entity’s name is needed. One way of getting to a name is by using the Get record action. An id/GUID from a trigger’s output can be used as dynamic content in the Get record action. The output of that action will then include the entity name in plural and the id/GUID of the related record.

3. Get record action to get to all the values of the created record.
4. Entity name with id/GUID in the Get record action’s output.

To extract the string value from @odata.editLink, an expression is needed. I have used a compose action for the expression and then use the output of the compose in the following action that creates a project task. The expression itself isn’t really “citizen developer” friendly but it does get the job done. If you copy this somewhere for future reference, the only thing that you need to change in the expression is the name of the Get record action. To get the entity name and id/GUID, a first+split+last+split is used:

first(split(last(split(body('Get_a_Project_record')?['@odata.editLink'],'')),','))
5. The Flow and its actions.

I’ve made a short video about this as well. I hope this small trick helps you reference records more easily! Kudos to MVP Sara Lagerquist for helping me out!

Referencing records when using the CDS (current environment) connector in Flow.
Disclaimer:
All my blog posts reflect my personal opinions and findings unless otherwise stated.

16 thoughts on “Referencing records when using the Common Data Service (current environment) connector”

  1. Do you think this behaviour in the new CDS current environment connector is a bug versus the ‘old’ CDS connector ? I don’t see any obvious use case for having to construct the ‘/myentity(GUID)’ style.

    1. Hi Phil. I can confirm that the OData ID requirement is by design. Let’s hope the product team improves the user experience in the near future.

  2. Hi Antti,

    Do you know if the FetchXML query is also affected by this somehow?

    I’m trying to replace a hardcoded GUID in the List records (current environment) action FetchXML query with a variable. However, when I do that it’s no returning anything. It’s working fine with the hardcoded value.

    1. I have to admit I’ve not used FetchXML with the new connector yet. Please let me know what you find out.

  3. I eventually got it working using the variable. However, I have no idea what I did different though ?‍♂️

  4. Hi, thank you for your article. Very well explained.

    Do you have a hint how to handle empty lookups?
    I tried using something like
    if(not(equals(variables(‘competitor’), ”)), concat(‘competitors(‘, variables(‘competitor’), ‘)’), null)
    but it does not work. It seems when the lookup field is touched by the flow the CDS expects nothing like null.

    1. Hi Lars and thanks for the feedback. I have to admit that I don’t have an answer to that off the top of my head. Usually I just try different things in Flow until I get the result I’m looking for 🙂 It’s all trial and error. I’ll put some time aside to do some testing around this at some point.

  5. Thank you for the article. Ive been trying something similar and keep getting a syntax error. do you happen to know if anything changed since you’ve written this article?

  6. Hi Antti
    I have tried using the compose action and entered the expression as per your video/post, it says invalid expression.
    first(split(last(split(body(‘my_Get_record_action’)?[‘@odata.editLink’],”)),’,’))

    Could you advise me please?

    Thanks
    Arjun

    1. Hi Arjun. The problem is most likely with the apostrophe.

  7. Hi Antti

    Thank you for this – I have been hunting around for a day trying to fix this problem.

    This blog finally nailed the problem.

    Thanks

    Nigel

  8. Hi,
    I have to Create a new Row in Dynamics 365 from an existing record. Thus, I have created a Flow with Get a Row and Create a Row action, but it doesn’t populate all the fields in the new record. Some of the columns in the existing record are referenced from other tables and are set a Regarding.

    If I add Table (entity) in front of Email address (emails) or Customer Attendance (contacts). It gives an error.

    The supplied reference link — /contacts() — is invalid. Expecting a reference link of the form /entityset(key).

Comments are closed.