How to Set Lookup Column Value in Microsoft Dataverse Connector in Cloud Flows

If you're using Microsoft Dataverse connector in your flow and getting the following errors, that means you are either

  1. setting the GUID value directly or
  2. not providing a correct plural version of entity schema name.

Empty segment encountered in request URL. Please make sure that a valid request URL is specified.
Resource not found for the segment xxxxx
1. In Microsoft Dataverse (legacy) connector, you can just set the GUID value of the record to populate the lookup value of the column. For polymorphic lookups, you will have an additional Type dropdown column (e.g. Customer Type) to choose the entity type of the record that you are setting.

But in the new Microsoft Dataverse connector, you need to provide the type of entity even if the lookup is just normal lookup to a single entity. For polymorphic lookups, there will be multiple columns for each entity type (e.g. Customer (Accounts) and Customer (Contacts) ) and you need to fill up the correct entity type that you are trying to populate. (and you still need to provide the entity type). Imagine if you are creating one of the activity records (e.g. Task) in the environment with a lot of entities enabled for Activities, you will see a lot of Regarding (xxxxxx) columns in your flow step.


2. Don't be fooled by the plural display name of the entity which is shown beside the field label. The EntitySetName that you need to provide is case sensitive and you cannot use that plural display name (Contacts) or entity logical name (contact). As mentioned in Dynamics CRM Tip of the Day #1311, what you need to use is the plural version of the entity schemaname (aka EntitySetName) followed by the GUID enclosed in parentheses. <<EntitySetName>>(<<RecordGUID>>)
e.g. contacts(<ContactID>)


For out of the box entities, the EntitySetName is the same as the plural display name for most of them. But things get tricky when you are trying to populate the value for the custom entity. You may be able to add 's', 'es', 'ies', etc. but how the system defines the EntitySetName is not perfect for all scenarios. (e.g. the EntitySetName of my lzw_journey entity is lzw_journeies)

In order to get the so-called EntitySetName, you can either search from
[Organization URI]/api/data/v9.1
e.g. https://contoso.crm.dynamics.com/api/data/v9.1

or replace the <<EntityLogicalName>> in the following URL format to get it for a particular entity
[Organization URI]/api/data/v9.1/EntityDefinitions(LogicalName='<<EntityLogicalName>>')?$select=EntitySetName
e.g. https://contoso.crm.dynamics.com/api/data/v9.1/EntityDefinitions(LogicalName='contact')?$select=EntitySetName

Another easier way to get the EntitySetName is by using the Metadata Browser for Dynamics 365/Power Apps Chrome browser extension.
UPDATE2: You can now set the null value to the lookup column by using the Microsoft Dataverse connector.

If you set the null value or the optional lookup value from another record which can potentially be empty in Microsoft Dataverse connector, you will get the following error.
An error occurred while validating input parameters: Microsoft.OData.ODataException: The 'odata.bind' instance or property annotation has a null value. In OData, the 'odata.bind' instance or property annotation must have a non-null string value.
The error message is the same as setting null for single-valued navigation property using Xrm.WebApi but I am not sure it is possible/necessary to use a DELETE request to remove a reference to an entity as mentioned in the Microsoft documentation.

There is a workaround for that issue and you can refer to it in my other blog post.

UPDATE: As one of the commenters, manish, suggested, setting NULL value of the single lookup column can be done in the same way as web API calls. All you need to do is to use HTTP Request with Azure AD and DELETE method.
Format of that is : /api/data/v9.1/incidents(GUID)/xxxx_InternalContactId/$ref
where xxxx_InternalContactId is the name of Navigation Property linked with InternalContact.

Or we can use the Unrelate records function too.

But it is not working for most of the scenarios that I encounter such as clearing multiple lookup fields in one API call (without multiple Unrelate/Delete records actions), or the most common issue for me is passing the GUID from another step which is an optional lookup field (so that the value may/may not be null)
While you're at here, please check out and vote for my submission at Power Automate Ideas regarding that.
https://powerusers.microsoft.com/t5/Power-Automate-Ideas/Allow-Setting-null-value-to-the-lookup-field-in-Common-Data/idi-p/427649


Comments

  1. Hi Linn,

    I was curious after checking your post and wondering if there is any way to set lookup as null and found that it works the same way as web api calls. All you need to do is to use HTTP Request with Azure AD and DELETE method .

    Format of that is :

    /api/data/v9.1/incidents(GUID)/xxxx_InternalContactId/$ref
    where xxxx_InternalContactId is the name of Navigation Property linked with InternalContact.

    Thanks

    ReplyDelete
    Replies
    1. Thanks for the suggestion, manish.
      That really works but it is not pratical for most of the scenarios that I need such as clear multiple lookup fields in one API call (without multiple Unrelate/Delete records actions), or the most common issue for me is passing the GUID from another step which is an optional lookup field (so that the value may/may not be null)

      If you agree with that, please go and vote for my submission at Power Automate Ideas. 😁
      https://powerusers.microsoft.com/t5/Power-Automate-Ideas/Allow-Setting-null-value-to-the-lookup-field-in-Common-Data/idi-p/427649

      Delete
    2. Hi Linn,

      I am wondering if you are using CDS or CDS(Current) . Just now I tried using Update a record action using CDS and setting the lookup to null works for me . Please let me know if it works for you.

      Thanks

      Delete
    3. Please use Expression and type null

      Delete
    4. It is CDS (Current) that is having a problem with setting null to lookup field.
      CDS works fine but I want to avoid using it as much as possible so that I can deploy the flow to the target environment without re-authorising the connection. 😁

      Delete
  2. Thanks Linn. It works like a charm !!

    ReplyDelete
  3. Hi Linn! Great post. Could you kindly tell me what I am doing wrong in this case? I am trying to populate my lookup field in CRM with data coming from Cosmos DB.

    For instance, I have a field within CRM called LEAD PM
    When I am in my logic app, I add this parameter, which is Lead PM and then when I add the dynamic field which contains my values, this fails to work.

    I am doing this:
    Lead PM(dynamicfield)

    and this is not working. Please add some suggestion. Thank you

    ReplyDelete
    Replies
    1. As mentioned in the blog post, it needs to be prefixed with the plural version of the entity schemaname (aka EntitySetName)
      What is the entity type of "Lead PM"?

      Is it the Contact entity? If so, it should be something like this:
      contacts(dynamicfield)

      Or is it the User entity? If so, it should be something like this:
      systemusers(dynamicfield)

      If it is the custom entity, find out the EntitySetName from API URL.
      [Organization URI]/api/data/v9.1

      Delete
  4. Hi, it's nice to see your blog. But I have a question can I populate guid to the lookup value of the field?

    ReplyDelete
    Replies
    1. Yes, you can populate the GUID value to the lookup field with <>(<>) format as mentioned in the blog post.
      e.g. contacts(a40675ed-84bc-43ca-bf4d-57e98d49d58b)

      Delete
  5. Hi Linn,
    I know this is a somewhat older article but I just wanted to say thank you for your contribution here. I've just spent the better part of 4 hours trying to debug this issue and every other article I read neglected to point out the need to use the EntitySetName and not the plural display name. That guidance and also the helpful API link to identify the Set name made all the difference in the wee hours of the morning. Thank you!

    ReplyDelete
    Replies
    1. I'm glad it helped to solve your problem 😊
      I really appreciate that you took some time to leave this comment. It really made my day. ☺️

      Delete
  6. Hi Lynn,

    Great article thanks. When referencing the lookup table do you have to use the GUID or can you just use a name field.
    For instance I want to reference the Contact Name "John Smith" rather that an ID 8046dfOAB......

    This is important for me becuase I am using the flow across different environments and have to keep getting a different GUID for the same Table (but in different environments)

    ReplyDelete
    Replies
    1. Hey dlutchy,

      When referencing the lookup table do you have to use the GUID only. The name can be duplicate and based on how the MS Dataverse API works, GUID is required to populate the lookup column value.

      Normally, we create the rows of the reference table (e.g. Country) with a script or tool so that the GUID is same across different environments. Otherwise, you will have to "List rows" and find the GUID of the row by name before referencing the lookup.

      Delete
  7. Thanks a ton! at last your blog solved my problem. The issue is with the SetName and the Plural Name, everywhere it's mentioned as Plural name but you have explained it clearly. Thanks again!

    ReplyDelete
    Replies
    1. I'm glad you learnt about the EntirySetName from my blog post. 😊

      Delete
  8. This blog post is a magic. Exactly what I wanted. Thanks a lot Linn.

    ReplyDelete
    Replies
    1. Thanks for your comment, Ramesh. Glad to know that it helps.

      Delete
  9. Hi Linn

    I am trying to populate owner field on opportunity entity from the excel records.
    Only name of owner is given, no guid.

    Can you please help me with the syntax to set the owner lookup field from the name of owner.

    Thanks in advance

    ReplyDelete
    Replies
    1. To retrieve the GUID for the owner, you will need to call List Rows action on the Users table with the filter "fullname eq <>" and get the GUID of the matching record.

      Delete

Post a Comment