Archive for June 9, 2012

Deleting notes attachments using jscript in CRM 2011


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;‘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”);






The maximum array length quota has been exceeded – Error in WCF service

June 9, 2012 1 comment


I was getting below exception when I call a WCF service from my plug – in

There was an error deserializing the object of type XYZ. The maximum array length quota (16384) has been exceeded while reading XML data

Below was my requirement,

  • I have to send emails with attachments from my plugin
  • So I built a custom WCF Email service
  • From the plug-in we are calling service method by passing object

I have no clue about the error, because I already given maximum reader quote values in my service configuration (Refer below)

Service Configuration:- 



<binding name=”basicHttp_EmailService” openTimeout=”00:30:00″

receiveTimeout=”00:30:00″ sendTimeout=”00:30:00″ maxBufferSize=”2147483647″

maxBufferPoolSize=”2147483647″ maxReceivedMessageSize=”2147483647″>


maxDepth=”2147483647” maxStringContentLength=”2147483647

maxArrayLength=”2147483647” maxBytesPerRead=”2147483647




<service name=”EmailService“>

After spending couple of hard hours I found the reason & fix for the issue


  • My service is simply ignoring my binding “basicHttp_EmailService” and it’s always taking default binding
  • Reason is
    • My configuration service name does not match with service name in Service Host
    • The name I given is “EmailService” where it has to be “XYZ. EmailService”

Fix :-

  • Right click your “.svc” file and choose “View Markup”
  • Copy the Service name and paste it in your service name
WCF Service Host

WCF Service Host

  • Now my Service configuration looks below

<service name=”XYZ.EmailService“>