Search code examples
c#httpdynamics-crmdynamics-crm-webapi

Problems setting related reference while uploading attachments to Dynamics CRM


I'm having some problems sending my attachment. It looks like this:

{
    "filename": "Test.txt",
    "subject": "Test",
    "mimetype": "text/plain",
    "documentbody": "SABlAGwAbABvACAAVwBvAHIAbABkAA==",
    "[email protected]": "/accounts(3ba2f6ab-3849-e811-a83b-000d3a2b2acb)",
    "isdocument": true
}

The error I get:

"error": {
    "code": "0x0",
    "message": "An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'objectid' 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."

This as per documentation found here: https://learn.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/create-entity-web-api#associate-entity-records-on-create

Any clue what is wrong here? Am I defining the relation between the annotation and account wrong?


Solution

  • This works without any issue. [email protected] is absolutely necessary because objectid can store any entity. Read more

    var entity = {};
    entity.subject = "arun test";
    entity["[email protected]"] = "/accounts(4B91608D-3C5A-EA11-A811-000D3A5A1CAC)";
    entity.notetext = "blah blah";
    entity.filename = "arun.txt";
    entity.documentbody = "SABlAGwAbABvACAAVwBvAHIAbABkAA==";
    entity.isdocument = true;
    
    Xrm.WebApi.online.createRecord("annotation", entity).then(
        function success(result) {
            var newEntityId = result.id;
        },
        function(error) {
            Xrm.Utility.alertDialog(error.message);
        }
    );