Tuesday, August 18, 2015

CRM 2013/2015 Using addCustomFilter() VS addCustomView()

Tuesday, July 28, 2015

CRM 2011/2013/2015 Javascript: Get Logged in User Full Name

CRM 2011

 function getUserFullName() {  
   var serverUrl = getCrmServerUrl();  
   var userRequest = GetRequestObject();  
   userRequest.open("GET", serverUrl + "/SystemUserSet(guid'" + Xrm.Page.context.getUserId() + "')?$select=FullName", false);  
   userRequest.setRequestHeader("Accept", "application/json");  
   userRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");  
   userRequest.send();  
   if (userRequest.status === 200) {  
     var retrievedUser = JSON.parse(userRequest.responseText).d;  
     var userFullName = retrievedUser.FullName;  
     return userFullName;  
   }  
   else {  
     return "";  
   }  
 }  
 function getCrmServerUrl() {  
   if (Xrm.Page.context.getClientUrl) // CRM 2011 UR 12+ and CRM 2013  
   {  
     serverUrl = Xrm.Page.context.getClientUrl() + "/";  
   }  
   else // CRM 2011 UR 11 or below  
   {  
     serverUrl = Xrm.Page.context.getServerUrl();  
   }  
   // Adjust URL for differences between on premise and online  
   if (serverUrl.match(/\/$/)) {  
     serverUrl = serverUrl.substring(0, serverUrl.length - 1);  
   }  
   return serverUrl + "/XRMServices/2011/OrganizationData.svc";  
 }  
 function GetRequestObject() {  
   if (window.XMLHttpRequest) {  
     return new window.XMLHttpRequest;  
   }  
   else {  
     try {  
       return new ActiveXObject("MSXML2.XMLHTTP.3.0");  
     }  
     catch (ex) {  
       return null;  
     }  
   }  
 }  


CRM 2013/2015

Xrm.Page.context.getUserName()

Thursday, July 9, 2015

How to Analyze the Performance of Dynamics CRM

The Performance Tool offers a simple and efficient method to analyze (and improve) the performance of Microsoft Dynamics CRM online and on premise environments.
You do need to have CRM 2013 SP1(or above) or 2015. It can be used on both forms and views.
The following steps activates this hidden feature.
Open a CRM form from your browser (IE or Chrome). For example, open an Account form.
Press Ctrl + Shift + Q to view the performance analyzer. This analyzer pop up window appears on your browserAnalyze Performance of CRM
To activate the tool, click the Enable button.
Press F5 to refresh your CRM form. The Performance analyzer will close.
Press Ctrl + Shift + Q to open the performance analyzer
Analyze performance of Dynamics CRM

What does this mean?

The different sections are all code that is triggered prior to a user having a functioning form to work on.
When an environment has many customizations, plug-ins, business rules, iframes or subgrid on a form, this is a great way to determine how quickly it is loading.The time is a breakdown of milliseconds.
In addition to the graphical view, when you click the “Select Major” button you’ll also see the breakdown in a text format.
  • Form Load Start (> 0 ms)
  • Read-Ready (> 1272 ms)
  • Initialize Controls – ViewportInlineEditControlInitializer (> 4583 ms)
  • Initialize Controls – NonViewportFormBodyInlineEditInitializer (> 4954 ms)
  • Initialize Controls – DeferredQuickFormInlineEditInitializer (> 5106 ms)
  • Onload Handler Start (> 5406 ms)
  • Onload Handler Finish (> 5579 ms)
  • Form Full Controls Init (> 5663 ms)
Finally, it is a good idea to disable the tool by clicking the “Disable” button when you have completed your analysis.

How to Close a Form in CRM 2013 using javascript

With reference to CRM 2013 SDK, following is the code snippet to close the form.

Xrm.Page.ui.close();

Please note the following important points.

"The HTML Window.close method is suppressed. To close a form window you 

must use this method. If there are any unsaved changes in the form the user 

will be prompted whether they want to save their changes before the window closes." 

( Ref: CRM 2013 SDK )


Whereas if we need to save the record using javascript, 

we could use the same methods which we were using in CRM 2011.

Xrm.Page.data.entity.save( null | "saveandclose" |"saveandnew" );

 

Arguments values:


save()

If no parameter is included the record will simply be saved. This is the equivalent of using the 

Save command.


save("saveandclose")

This is the equivalent of using the Save and Close command.


save("saveandnew")

This is the equivalent of the using the Save and New command.

( Ref: CRM 2013 SDK )

Monday, July 6, 2015

Loading dependent jscript libraries in ribbon button’s execution CRM 2013

I have a ribbon button on my “Quote” main grid .

I am calling function “sayHello” which is in my web resource “Quote_ribbon” by defining custom action like below.


FunctionName=”sayHello”
Now the problem is, I need to call another method from my “sayHello” function, which is in other web resource “common”.

Solution :-
The solution is simple. We can add all the required libraries to node like below
 FunctionName=”isNaN” 
Note – Since requires a function name, pass “isNaN”.

If you refer 3rd party libraries like jquery or XRMToolkit in your library then just add those in the actions.

Make sure you use the correct order when configuring the ribbon actions.

The dependent script files has to be ordered before the actual script file.


Wednesday, July 1, 2015

Report Parameter Error(the value expression for the query parameter refers to non-existing report parameter . letters in the names of parameters must use the correct case)

 I use the @Region in the dataset query, then modify the parameter name from Region to region, then modify the @Region to @region in the dataset query. When we render the report, it throws an error message that “The Value expression for the query parameter '@region' refers to a non-existing report parameter 'Region'. Letters and names of parameters must use the correct case.” But we couldn’t find anything about Region in the Report Data tab.

the query parameter @region still use the =Parameters! Region.Value as value in the XML file. Even after removing them from the Data tab, the fields might still be in the and section.  Right-click the report in the Solution Explorer and go to "View Code" and double-check if Region is still present in those sections of the XML.
What's more, the issue may be caused by the cache. Please try to delete the reportname.rdl.data file in the report project folder before preview the report.

Monday, June 29, 2015

Principal user is missing prvReadComplexControl privilege

Recently we have upgraded CRM 2011 to CRM 2013 and we were getting generic errors "Insufficient permissions" when we open few entity forms in CRM

On debugging after switching on CRM trace logs we have found that the user is missing some privilages. Below is the execption we got.

>UNEXPECTED: no fault?
[2015-06-29 01:21:28.151] Process: w3wp |Organization:00000000-0000-0000-0000-000000000000 |Thread:  346 |Category: Platform |User: 00000000-0000-0000-0000-000000000000 |Level: Error |ReqId: 33a6e86d-6e32-48b9-8065-d3aa8f576c42 | ExceptionConverter.ConvertMessageAndErrorCode  ilOffset = 0x23B
>System.Web.HttpException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #41EB8FD7: System.Web.HttpException (0x80004005): Error executing child request for /CRMUPGV5/_forms/read/page.aspx. ---> System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> Microsoft.Crm.CrmException: Principal user (Id=40f2886d-c8da-e111-80f0-005056ae010b, type=8) is missing prvReadComplexControl privilege (Id=a4736385-9763-4a64-a44b-cd5933edc631)
>   at Microsoft.Crm.Application.Platform.ServiceCommands.PlatformCommand.XrmExecuteInternal()
>   at Microsoft.Crm.Application.Platform.ServiceCommands.RetrieveCommand.Execute()
>   at Microsoft.Crm.Caching.ComplexControlLoader.LoadCacheData(Guid key, IOrganizationContext context)
>   at Microsoft.Crm.Caching.CrmMultiOrgCacheBase`2.CreateEntry(TKey key, IOrganizationContext context)
>   at Microsoft.Crm.Caching.CrmMultiOrgCacheBase`2.LookupEntry(TKey key, IOrganizationContext context)
>   at Microsoft.Crm.Application.Components.Sdk.InlineEditControls.Web.CompositionLinkControl.GetFlyOutDescriptor()
>   at Microsoft.Crm.Application.Components.Sdk.InlineEditControls.Web.LinkControl.GetRequiredColumns(Int32 entityTypeCode)
>   at Microsoft.Crm.Application.Forms.CompositeControlVisitor.HandleColumnProvider(Control control, FormDescriptor formDescriptor)
>   at Microsoft.Crm.Application.InlineEdit.Mediators.FormMediator.AddControlProperties(ICrmControl crmControl, ControlDescriptor controlDescriptor)
>   at Microsoft.Crm.Application.InlineEdit.Mediators.FormMediator.ProcessControlHierarchy(Action`2 controlHandler)
>   at Microsoft.Crm.Application.InlineEdit.Mediators.FormMediator.GetInstance(FormFactor formFactor, FormDescriptor descriptor, Guid processId, Int64 processVersionNumber, IOrganizationContext organizationContext)
>   at Microsoft.Crm.Application.InlineEdit.Mediators.FormMediator.GetInstance(FormFactor formFactor, Guid formId, Guid processId, Int64 processVersionNumber, IOrganizationContext organizationContext)
>   at Microsoft.Crm.Application.InlineEdit.ReadFormDataBuilder..ctor(String recordId, String entityTypeCode, Guid formId, FormFactor formFactor)
>   at Microsoft.Crm.Application.Pages.Common.ReadFormPage.PopulateFormDescriptorAndDataBuilder()
>   at Microsoft.Crm.Application.Pages.Common.ReadFormPage.OnPreInit()
>   at Microsoft.Crm.Application.Controls.AppUIPage.OnInit(EventArgs e)
>   at Microsoft.Crm.Application.Controls.AppPage.OnInit(EventArgs e)
>   at System.Web.UI.Control.InitRecursive(Control namingContainer)
>   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>   at System.Web.UI.Page.HandleError(Exception e)
>   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>   at System.Web.UI.Page.ProcessRequest()
>   at System.Web.UI.Page.ProcessRequest(HttpContext context)
>   at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
>   at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
>   at System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean preserveForm)
>   at System.Web.HttpServerUtility.Transfer(String path)
>   at System.Web.UI.Control.PreRenderRecursiveInternal()
>   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>   at System.Web.UI.Page.ProcessRequest()
>   at System.Web.UI.Page.ProcessRequest(HttpContext context)
>   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
>   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)



The error seems to talk about some complex control in CRM to which the user does not have read privilege. Perplexed that you never heard of any ComplexControl entity in CRM?

However a little bit of search in SDK regarding this privilege and this is what I got from the SDK.
ComplexControl entity is for internal use only. However, users need read access to this entity in order to see the updated experience for lead and opportunity forms.
Still can’t find the complexcontrol entity? No worries. Open the security roles of the user who is getting this error.
Go to Customizations tab and search for the Process Configuration entity and assign the privileges for the security role. Check the below screenshot.




The SDK also clearly states out that this privilege is for Process Configuration entity.


Hope this helps someone who face similar problems!!!


Thursday, June 18, 2015

CRM 2011 Quick Find Search results grid not showing header data

We have faced an issue with quick search not showing header data. fields are visible but data is not visible in the grid.

We have a Quote OOB entity and Quote Part which is a custom entity and has 1:N relationship with Quote

In the main navigation we have the quote part entity displayed under sales.

When we initially open the quote part entity grid it shows all the fields of quote and quote part with all the data visible.

Once i search with one of the quote part field it shows the NO OF RESULTS correctly but it returns the Quote related fileds empty.

After log of research and trail and error method we have found that the Quick find configuration has a problem.

No Fields were selected in Quote part quick find (Find Fields)  After we select the few fields in the FIND COLUMNS it started returning the data for the Quote attributes. Weird but true.

This is no where documented in SDK. So thought it will be helpful for anyone else who face the same issue

Here are the screenshots showing the error






Tuesday, June 16, 2015

Reload Form in CRM 2013

CRM 2013 form will not reload the entire form after saving the record this is by design.
 so as a work around is to use "Xrm.Utility.openEntityForm" provided in SDK which is supported in all browsers.

Modified on Field in CRM will always be updated on CREATE and UPDATE of the record so we will register a function on Change of Modified on field.

function modifiedon_onChange() {
    reloadFormAfterSave();
}

function reloadFormAfterSave() {
    setTimeout(function() {
        Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
    }, 500);

}



Wednesday, April 1, 2015

Fetch Xml to Get Workflow Id by Name

 <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>  
  <entity name='workflow'>  
   <attribute name='workflowid' />  
   <attribute name='name' />  
   <attribute name='category' />  
   <attribute name='primaryentity' />  
   <attribute name='statecode' />  
   <attribute name='createdon' />  
   <attribute name='ownerid' />  
   <attribute name='owningbusinessunit' />  
   <attribute name='type' />  
   <order attribute='name' descending='false' />  
   <filter type='and'>  
    <condition attribute='type' operator='eq' value='1' />  
    <filter type='or'>  
     <condition attribute='category' operator='eq' value='0' />  
     <filter type='and'>  
      <condition attribute='category' operator='eq' value='1' />  
      <condition attribute='languagecode' operator='eq-userlanguage' />  
     </filter>  
    </filter>  
    <condition attribute='name' operator='eq' value='WORKFLOW NAME' />  
   </filter>  
  </entity>  
 </fetch>  

Thursday, March 5, 2015

New Line in SSRS Text box

=Fields!AddressLine1 + VBCRLF + Fields!AddressLine2 + VBCRLF + Fields!AddressLine3 

OP:
 Address1
 Address2
 Address3


Note: If VBCRLF is used first or last part the expression, it has no impact on result. If you want a line in the first or last, then use one more extra VBCRLF.

Thursday, February 26, 2015

Switch HTTP request object for browser compatability

 function GetRequestObject() {  
   if (window.XMLHttpRequest) {  
     return new window.XMLHttpRequest;  
   } else {  
     try {  
       return new ActiveXObject("MSXML2.XMLHTTP.3.0");  
     }  
     catch (ex) {  
       return null;  
     }  
   }  
 }