Advertisements
Home > CRM 2011, JScript > Deleting notes attachments using jscript in CRM 2011

Deleting notes attachments using jscript in CRM 2011

Hi,

In CRM, we can add files as attachments to the Notes.

Notes with attachment

Notes with attachment

  • All the notes get saved in to “Annotation” entity in the data base.
  • The attachment information get saved in to below columns of “Annotation” entity
    • Document Body
    • File Name
    • File Size
    • Is Document
Notes with attachments - Data base columns

Notes with attachments – Data base columns

Deleting attachments using  script:-

To delete the attachment using jscript,

  • Update the “Document Body,File Name,File Size” fields to null
  • And “IsDocument = false” using OData as below

function deleteAttachments(){

var notesId = {GUID of notes};

var objNotes = new Object();

objNotes.DocumentBody = null;

objNotes.FileName = null;

objNotes.FileSize = null;

objNotes.IsDocument = false;

updateRecord(notesId, objNotes, “AnnotationSet”);

}

function updateRecord(id, entityObject, odataSetName) {

var jsonEntity = window.JSON.stringify(entityObject);

var serverUrl = Xrm.Page.context.getServerUrl();

var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;

var updateRecordReq = new XMLHttpRequest();

var ODataPath = serverUrl + ODATA_ENDPOINT;

updateRecordReq.open(‘POST’, ODataPath + “/” + odataSetName + “(guid'” + id + “‘)”, false);

updateRecordReq.setRequestHeader(“Accept”, “application/json”);

updateRecordReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);

updateRecordReq.setRequestHeader(“X-HTTP-Method”, “MERGE”);

updateRecordReq.send(jsonEntity);

}

🙂

 

Advertisements
  1. May 8, 2015 at 8:02 PM

    where can i find the GUID of notes :/

  2. May 8, 2015 at 8:02 PM

    Where can i find the GUID of notes

  1. No trackbacks yet.

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

%d bloggers like this: