Skip to main content

Notifications

Microsoft Dynamics CRM forum
Answered

XRM Web Api (create record) - issues creating a note (annotation) with an object ID specified

Posted on by 15

I've been looking to add a feature where using client side script, we would like to create a note (annotation).  I've been able to create a note but haven't been able to assign it to a custom entity.  Here is the client side code we're using:

var clientID = formContext.getAttribute("client").getValue()[0].id;

        // define the data to create new annotation
        var data =
            {
                "subject": "Client Interaction",
                "notetext": "Client Interaction logged",
                "isdocument": false,
                "objectid":
                {
                    "logicalname": "custom_client",
                    "custom_clientid": clientID
                }
            }

        // create annotation (note) record
        Xrm.WebApi.createRecord("annotation", data).then(
            function success(result) {
                console.log("Note created with ID: "   result.id);
                // perform operations on record creation
            },
            function (error) {
                console.log(error.message);
                // handle error conditions
            }
        );

I'm successfully able to create the annotation (note) if I remove the objectid property but we really want to create the note so it's regarding (linked) to the custom entity client.  The error we see in the console is:

An error occurred while validating input parameters: Microsoft.OData.ODataException: Does not support untyped value in non-open type.

Any help would be greatly appreciated!

  • HerbMa Profile Picture
    HerbMa 15 on at
    RE: XRM Web Api (create record) - issues creating a note (annotation) with an object ID specified

    Hi Clofly,

    Thank you so much!  That did the trick, I misunderstood the specs for objectid.  I updated my code set as per your suggestion and it works perfectly.  Many thanks!  (I was stuck for quite some time).

    Herb

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,196 on at
    RE: XRM Web Api (create record) - issues creating a note (annotation) with an object ID specified

    Hi HerbMa,

    The error indicates that we are passing a property of a JSON object(the data variable in your code) that doesn't exist on the data model(objectid can't be used directly).

    Instead, please change the data object to following:(e.g: I have a custom entity called Doctor.)

    var data = 
    {
        "subject": "Client Interaction",
        "isdocument": false,
        "notetext": "Client Interaction logged",
        "objectid_new_doctor@odata.bind": "/new_doctors(3f4f2e69-1356-eb11-a812-00224816bc2d)",
        "objecttypecode": "new_doctor"
    };
    
    Xrm.WebApi.online.createRecord("annotation", data).then(
        function success(result) {
            var newEntityId = result.id;
            console.log("Note created with ID: "   newEntityId);
        },
        function(error) {
            Xrm.Utility.alertDialog(error.message);
        }
    );

    pastedimage1610594357421v1.png

    You can refer to this article for more details about how to create annotation and associate it to an entity.

    https://community.dynamics.com/365/b/dynamics365enterprisecloudfronts/posts/create-notes-attachment-using-webapi

    Regards,

    Clofly

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,469 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans