Update Note (Annotation) using Jscript in Microsoft Dynamics CRM 2011

Posted: October 7, 2012 in CRM 2011, Jscripts

Update Note using Jscript

In my example i’m going to update notetext and note subject in CRM.

To perform an ODATA call, we need to add jquery1.4.1.min and json2 files in your Form Properties. You can get those files from sdk.
path – \sdk\samplecode\js\restendpoint\jqueryrestdataoperations\jqueryrestdataoperations\scripts.

function UpdateNotes() {
    // create notes object
    var objNotes = new Object();
    objNotes.Subject = "Note Subject Updated";
    objNotes.NoteText = "First Note Updated";

    // Pass the guid of the annotation.
    var annotationId = 'A1A04803-6310-E211-8C0E-78E3B511A681';
    var jsonEntity = window.JSON.stringify(objNotes);

    var serverUrl = Xrm.Page.context.getServerUrl();
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc/AnnotationSet";
    var ODataPath = serverUrl + ODATA_ENDPOINT;
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: ODataPath + "(guid'" + annotationId + "')",
        data: jsonEntity,
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
            XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
        error: function (xmlHttpRequest, textStatus, errorThrown) {
            alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s