Maximum rollup fields in MS CRM

You are limited to a maximum of 10 Rollup fields per Entity and a Maximum of 100 per organization.  On Premise deployments can modify this but online cannot.  A roll up field cannot include other rollups.

Two more interesting points on Rollup fields:

1. Rollup fields cannot be audited.
2. Rollup fields can include hierarchy data.

What is fetchXML?

FetchXML is proprietary query language used in Microsodt Dynamics CRM online or on-premises to retrieve records from an entity. It is depends on schema language. In terms of capabilities it is equal to queryexpression,  and it has addition feature of save query as user-owned saved view in userQuery system entity and and as an organization-owned saved view in the savedquery entity.

We will run FetchXML and retrieve records using RetrieveMultiple method by creating FetchExpression object.

Below is the sample code on running fetchXML.

String fetchXML=@"<fetch mapping='logical'>
   <entity name='account'>
      <attribute name='accountid'/>
      <attribute name='name'/>
</entity>
</fetch>";

FetchExpression fetchExpression=new FetchExpression(fetchXML);
EntityCollection entityCollection=service.RetrieveMultiple(fetchExpression);


Note: Don’t retrieve all attributes in a query because of the negative effect on performance. This is particularly true if the query is used as a parameter to an update request. In an update, if all attributes are included this sets all field values, even if they are unchanged, and often triggers cascaded updates to child records.

MS CRM new form rendering or Turbo form rendering

To improve the performance of form rendering, Microsoft dynamics CRM come up with new form rendering engine since Online 2015 update 1 (V7.1). Before that we had legacy rendering where everything will works on sequence order.

Turbo form rendering or new form rendering forms will load significantly faster and more efficient. Turbo form rendering has same support as legacy forms are having for client scripting, form XML Schema that means no fundamental changes made in terms of what forms generally does.

So what are the main changes?
Changes were mainly based on optimizing the form loading process. Optimization have been done on mainly two ways.
  1. Loading process of the form
  2. Handling of Cache.

Loading process of the form: Here optimization has been done by running maximum no of operations parallel to avoid browser idle time, amount of content being cached has been increased, event part of rendering process have been moved partially to server and optimized the initialization of controls.

CRM forms do have iframes internally to load webresources, earlier these iframes are discarded and reloaded on each form load. But in new design iframes will not  be discarded but keep them around, as common scripts are already parsed need not load again. But for custom scripts and ISV scripts new design will load these in new iframe which will be discarded when form closes. Earlier, these would be loaded in the same iframe as the form.

Examples of things that will break:
  • Any attempt to access DOM in the content iframe using JS, jQuery or other 3rd party libraries (document.getElementById() or jQuery selectors)
  • Creating a new HTML content in the parent window for persistent content (and assumed that the parent window was the main CRM iframe.
  • Window.load, parsing iframe/form URL
  • Attempting to use unsupported (non-XRM) APIs, especially undocumented ones that may have been shipped with CRM for internal usage only
  • Accessing window.parent() from a web resource that may assume for example there’s a variable set in the current window context. 


Below are the navigation details to enable or disable legacy rendering.


Settings -> Administration -> System Settings -> General. Select "Yes" under "Use legacy form rendering" to disable turbo forms or else select "No"

Retrieve more than 5000 records in MS CRM using fetch XML

When you use retrieve multiple to retrieve records from any entity, the maximum no of records returned by retrieve multiple is 5000. But there will be scenario we have to retrieve more than 5000, in those scenarios we should use paging as shown below.

private string RetrieveMoreThan500Records()
{
            EntityCollection caseCollection = new EntityCollection();
            try
            {
                var moreRecords = false;
                int page = 1;
                var cookie = string.Empty;
                string fetchXML = RetrieveCaseFetchXML();
                do
                {
                    var caseFetchXML = string.Format(fetchXML, cookie);
                    var collection = service.RetrieveMultiple(new FetchExpression(caseFetchXML));
 
                    if (collection.Entities.Count >= 0)
                    {
                        caseCollection.Entities.AddRange(collection.Entities);
                    }
 
                    moreRecords = collection.MoreRecords;
                    if (moreRecords)
                    {
                        page++;
                        cookie = string.Format("paging-cookie='{0}' page='{1}'", System.Security.SecurityElement.Escape(collection.PagingCookie), page);
                    }
                } while (moreRecords);
            }
            catch (Exception ex)
            {
            }

}

private string RetrieveCaseFetchXML()
{
            return @"<fetch {0} version='1.0' output-format='xml-platform'   mapping='logical' distinct='false'>
                      <entity name='incident'>
                        <attribute name='ticketnumber' />
                        <attribute name='incidentid' />
                        <order attribute='createdon' descending='false' />
                       </entity>
                    </fetch>";
}

Close an incident or case in MS CRM

To close incident record we need to update statecode, for this generally we do use SetStateRequest but this will works only for cancel the case or incident not for close or resolve. Below is the code snippet to close an incident.

                    CloseIncidentRequest closeIncidentRequest = new CloseIncidentRequest();
                    Entity incidentEntity = new Entity("incidentresolution");
                    incidentEntity.Attributes.Add("incidentid", new EntityReference("incident", caseId));


                    closeIncidentRequest.IncidentResolution = incidentEntity;
                    closeIncidentRequest.Status = new OptionSetValue(statusReason);
                    CloseIncidentResponse closeIncidentResponse = (CloseIncidentResponse)service.Execute(closeIncidentRequest);


Update statecode and statuscode in MS CRM

In general we do use update method of organization service to update any record in crm, but it doesn't work to update statecode or statuscode. Below is the code snippet we should use to update these fields.

                SetStateRequest setStateRequest = new SetStateRequest();
                setStateRequest.EntityMoniker = new EntityReference("your entity name", recordGuid);

                setStateRequest.State = new OptionSetValue(stateCode);
                setStateRequest.Status = new OptionSetValue(statusReason);

                SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setStateRequest);

Set session timeout in MS CRM

By default online session timeout is 1440 minutes or 24 hours. We can configure or set session timeout as per requirement as shown below.

Go to settings->Adminstration->System settingss->General Tab.


Under Set session timeout section, click on Set Custom radio so that, below text boxes will be enabled for you to set session timeout.


Featured Post

Improving MS CRM Performance

Performance on MS CRM is always a crucial thing and we may follow different ways to achieve the performance thing. Below is the one more a...