Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

POST Error: ODataPrimitiveValue was instantiated with a value of type 'Microsoft.OData.ODataEntityReferenceLink'

(0) ShareShare
ReportReport
Posted on by

I receive the following error when I trying to set up a new OData entry with a navigation property. The OData system I'm working on uses /ebecssvy_questionses(QUESTION_ID) as a navigation property. Here is the line that causes the error:

entity["ebecssvy_questionsid@odata.bind"] = "/ebecssvy_questionses(" + newId + ")";

Here is the error I receive when trying to POST the above entity using an XMLHttpRequest:

"error":{"code":"0x0","message":"An error occurred while validating input parameters: Microsoft.OData.ODataException: An ODataPrimitiveValue was instantiated with a value of type 'Microsoft.OData.ODataEntityReferenceLink'. ODataPrimitiveValue can only wrap values which can be represented as primitive EDM types.\r\n at Microsoft.OData.ODataPrimitiveValue..ctor(Object value)\r\n at Microsoft.OData.ODataValueUtils.ToODataValue(Object objectToConvert)\r\n at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.AttachODataAnnotations(IODataJsonLightReaderResourceState resourceState, String propertyName, ODataProperty property)\r\n at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.AddResourceProperty(IODataJsonLightReaderResourceState resourceState, String propertyName, Object propertyValue)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadEntryDataProperty(IODataJsonLightReaderResourceState resourceState, IEdmProperty edmProperty, String propertyTypeName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithValue(IODataJsonLightReaderResourceState resourceState, String propertyName, Boolean isDeltaResourceSet)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.<>c__DisplayClass9_0.b__0(PropertyParsingResult propertyParsingResult, String propertyName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.StartReadingResource()\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceSetItemStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementationSynchronously(PropertyAndAnnotationCollector propertyAndAnnotationCollector)\r\n at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)"}

I'm unsure what the issue is as I haven't worked with OData or CRM very extensively. The entity itself has all other properties cloned from a GET request of an existing record. I'm not sure how to fix this; Shouldn't entity.ebecssvy_questionsid@odata.bind be a primitive? Its value is a String, after all, and I would think a ODataEntityReferenceLink would be represented as a String. The ID is right, its the ID of the cloning target just incremented by one in the ID section that contains a random number. If more parts of the code or format of the OData are relevant, let me know, but both of those are quite large so I do not want to link them in their entirety.

  • RE: POST Error: ODataPrimitiveValue was instantiated with a value of type 'Microsoft.OData.ODataEntityReferenceLink'

    Ok I think I figured it out! I hadn't made the association between the question and the tab, and using CRM REST Builder's Association setting letting me create that association.

  • RE: POST Error: ODataPrimitiveValue was instantiated with a value of type 'Microsoft.OData.ODataEntityReferenceLink'

    Hm, I may have spoken too soon. It worked initially until I tried to update the ebecssvy_tabsid value, which is also suppose to have an odata binding. Adding the following line:

    entity["ebecssvy_tabsid@odata.bind"] = "/ebecssvy_tabses(" + entity._ebecssvy_tabsid_value + ")";;

    ...Produces the following error:

    {"error":{"code":"0x0","message":"An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'ebecssvy_tabsid' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.\r\n   at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadUndeclaredProperty(IODataJsonLightReaderResourceState resourceState, String propertyName, Boolean propertyWithValue)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithoutValue(IODataJsonLightReaderResourceState resourceState, String propertyName)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.<>c__DisplayClass9_0.<ReadResourceContent>b__0(PropertyParsingResult propertyParsingResult, String propertyName)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightReader.StartReadingResource()\r\n   at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceSetItemStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementationSynchronously(PropertyAndAnnotationCollector propertyAndAnnotationCollector)\r\n   at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n   at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n   at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n   at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n   at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)"}}

  • RE: POST Error: ODataPrimitiveValue was instantiated with a value of type 'Microsoft.OData.ODataEntityReferenceLink'

    Nice! I got that that generator working and the POST requests it made seem to work. Not sure why the generated one worked while mine didn't, but I'm currently comparing both to try to figure it out. Thanks!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: POST Error: ODataPrimitiveValue was instantiated with a value of type 'Microsoft.OData.ODataEntityReferenceLink'

    Hi Jared,

    1.Download it in following page:

    https://github.com/jlattimer/CRMRESTBuilder/releases 

    2. Go Settings > Solutions to import the file you just downloaded as solution:

    pastedimage1633326191951v1.png

    3.Refresh current page, then it will appear at the top of the page:

    pastedimage1633326252287v2.png

    Now, you can click it to open the tool to use it.

  • RE: POST Error: ODataPrimitiveValue was instantiated with a value of type 'Microsoft.OData.ODataEntityReferenceLink'

    I am unsure how to use this tool. Does it run within Dynamics 365 or should I be able to use it on my host machine?

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: POST Error: ODataPrimitiveValue was instantiated with a value of type 'Microsoft.OData.ODataEntityReferenceLink'

    Hi Partner,

    You can try to generate code through CRM REST Builder, which is a fantastic tool.

    --Download page: https://github.com/jlattimer/CRMRESTBuilder

    Example: Update 'Primary Contact' field in Account form.

    pastedimage1633066308123v2.png

    Create Request:

    pastedimage1633066366983v4.png

    Execute code.

    Test Result:

    pastedimage1633066142763v1.png pastedimage1633066425356v5.png

    But if the lookup field is custom not OOB, you need ensure using  schema name of lookup field.

    Example: Update custom lookup field in Account form.(Account and Custom entity is N:1 relationship)

    pastedimage1633068291372v7.png

    Edit code, then execute:

    pastedimage1633068620993v9.png

    pastedimage1633068487634v8.png

    Test:

    pastedimage1633068208266v6.png pastedimage1633068656299v10.png

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,703 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,433 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans