Archive for June, 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“>


“Query execution time exceeded the threshold” error in Plugins


In one of my requirement I was accessing SSRS service API from my plugin to render and read the report

When the plugin execute the code, I was neither getting the expected result nor any error.

To troubleshoot the problem I open the event viewer and I got a warning stating below

Query execution time of 30.1 seconds exceeded the threshold of 10 seconds. Thread: 30; Database: orgname_MSCRM

Reason :- 

  • My plugin registered on Post Update of Account
  • In my plugin, I was rendering and reading a report which has dataset with “Select * From Account”
  • So the problem is with DB lock
    • On update of ‘Account’, a lock establish
    • In the Plugin code, when I try to render report it tries to execute “Select” statement on “Account” we get the above error

Fix :-

  • I modified my Select statement in report dataset with “No Lock” statement

             i.e., Select * From Account (nolock)


Reading sub grid records using jscript in CRM 2011


In CRM 2011, we can show the related records in parent record form using sub grids.

For example below is ‘Contacts’ sub grid on ‘Account’ form

Contacts sub-grid

Contacts sub-grid

We can get the records count and read the cell values of sub grid using below script.

function getSubGridDetails() {

// Set subgrid schema name

var subGridName = ‘accountcontactsgrid’;

if (document.getElementById(subGridName)) {

var gridControl = document.getElementById(subGridName).control;

// Get records length

var countGridRecords = 0;

if (gridControl && gridControl.getRecordsFromInnerGrid()) {

countGridRecords = gridControl.getRecordsFromInnerGrid().length;

alert(“Subgrid records count – ” + countGridRecords);


// Read Cell Values By Row

for (var indxRow = 0; indxRow < countGridRecords; indxRow++)

for (var indxCell = 0; indxCell < gridControl.getRecordsFromInnerGrid()[indxRow][3].cells.length; indxCell++) {

alert(“Cell Value – ” + gridControl.getRecordsFromInnerGrid()[indxRow][3].cells[indxCell].outerText);