locked
MSCRM 2015 - Using javascript how to create entry in Notes section RRS feed

  • Question

  • Hi Team,

    In MSCRM 2015 - Using javascript how to create entry in Notes section.

    Thanks in advance.

    Regards,

    Sreenath

    Thursday, March 17, 2016 10:37 AM

Answers

  • function AddNotes(EntityName, EntityId,NoteText) {
        var serverUrl = Xrm.Page.context.getClientUrl();
        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
        var objAnnotation = new Object();
        var ODATA_EntityCollection = "/AnnotationSet";
        objAnnotation.NoteText = NoteText;
        objAnnotation.Subject = "Subject";

        var refAccount = new Object();
        refAccount.LogicalName = EntityName;
        refAccount.Id = EntityId;

        objAnnotation.ObjectId = refAccount;
        objAnnotation.ObjectTypeCode = refAccount.LogicalName;

        // Parse the entity object into JSON 
        var jsonEntity = window.JSON.stringify(objAnnotation);

        // Asynchronous AJAX function to Create a CRM record using OData 
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection,
            data: jsonEntity,
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
            }
        });
    }
    Thursday, March 17, 2016 11:46 AM