web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Cannot convert type 'Microsoft.Xrm.Sdk.OptionSetValue' to 'Microsoft.Xrm.Sdk.EntityReference'

(0) ShareShare
ReportReport
Posted on by 515

Hi

During a code upgrade (to 8.2)  I'm getting the following error.

Cannot convert type 'Microsoft.Xrm.Sdk.OptionSetValue' to 'Microsoft.Xrm.Sdk.EntityReference'

my code is

---

if (DBStatus.custom_field != null)
InsertStatusHistory("Investigation Outcome Status", ((EntityReference)DBStatus.custom_field).Name, _caseID, service);

---

(EntityReference)DBStatus.custom_field).Name is the cause of the error

Can anybody let me know what the upgrade to this code should read like?

I have the same question (0)
  • Suggested answer
    Torrado Profile Picture
    1,270 on at

    Hello Lee-Martin,

    It seems that you are trying to set a value for a lookup attribute but not using the correct object properties. Probably you are using a constructor that cannot be used with earlier versions of Dynamics 365.

    You should use something like:

    entity.Attributes["lookupFieldName"] = new EntityReference(string logicalName, Guid id); 

    Hope this helps you.

    Please mark the answer as verified if helpful. That will help others in future.

     

  • Lee-Martin Profile Picture
    515 on at

    Thank you, but it is an optionset not a lookup

  • Torrado Profile Picture
    1,270 on at

    Hello,

    Then, please refer to this article, about how to set a value for OptionSet field: crmbusiness.wordpress.com/.../

    Hope this help you.

  • Suggested answer
    Wahaj Rashid Profile Picture
    11,321 on at

    Hi,

    Thank you for your query.

    If you are sure that the DBStatus.custom_field  is an option set, you should pass OptionSetValue or string label instead of Entity Reference (depending on your logic).

    You can get the OptionSet Label using Formatted values collection form your entity object.

    if (DBStatus.custom_field != null)
    {
        string dbStatusLabel = DBStatus.FormattedValues["custom_fiel_name"];
    
        InsertStatusHistory("Investigation Outcome Status", dbStatusLabel, _caseID, service);
    
    }

    Please note, above code is for your reference, you might need to modify it to match your logic.

    More details on getting formatted values:

    Get OptionSet Label using FormattedValues property of Entity in Plugin in CRM – Nishant Rana's Weblog

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 69 Super User 2026 Season 1

#2
BillurSamdancioglu Profile Picture

BillurSamdancioglu 55 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans