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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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.

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    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

  • Jared.Leonard Profile Picture
    on at

    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?

  • Community Member Profile Picture
    on at

    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.

  • Jared.Leonard Profile Picture
    on at

    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!

  • Jared.Leonard Profile Picture
    on at

    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)"}}

  • Jared.Leonard Profile Picture
    on at

    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.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 60 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 51

#3
Satyam Prakash Profile Picture

Satyam Prakash 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans