Thursday, November 07, 2013

Code snippet to increase Aggregate Query Record Limit


Use the code template from here

Code:
DeploymentServiceClient service = Microsoft.Xrm.Sdk.Deployment.Proxy.ProxyClientHelper.CreateClient(new Uri("http://crmtest/XRMDeployment/2011/Deployment.svc"));

                RetrieveAdvancedSettingsRequest request3 = new RetrieveAdvancedSettingsRequest()
                {
                    ConfigurationEntityName = "Deployment", ColumnSet = new ColumnSet(false)
                };
                RetrieveAdvancedSettingsResponse response3 = (RetrieveAdvancedSettingsResponse)service.Execute(request3);
                ConfigurationEntity configEntity = response3.Entity;

                ConfigurationEntity entity = new ConfigurationEntity();
                entity.LogicalName = "Deployment";
                entity.Attributes = new Microsoft.Xrm.Sdk.DeploymentAttributeCollection();
                entity.Attributes.Add(new KeyValuePair<string, object>("AggregateQueryRecordLimit", 50000));
                     
                UpdateAdvancedSettingsRequest request2 = new UpdateAdvancedSettingsRequest();
                request2.Entity = entity;
                service.Execute(request2);



Update the deployment service URL 

Code snippet to increase max records exported to excel


Use the code template from here

In the example below I am updating max records exported to excel.

Code:
QueryExpression qe = new QueryExpression("organization");
                qe.ColumnSet = new ColumnSet("maxrecordsforexporttoexcel");
                EntityCollection entColl = _service.RetrieveMultiple(qe);
                if (entColl.Entities.Count > 0)
                {
                    Entity ent = entColl.Entities[0];
                    ent["maxrecordsforexporttoexcel"] = 500000;
                    _service.Update(ent);
                }