OnLoad event for SubGrid in CRM 2015 Update 1

Till CRM 2011 we used to use Xrm.page.getControl(“grid”) to get a grid control available on form and perform any runtime activity like changing the view/query, etc. Also we were required to write the complete script on OnLoad even of form and add a timeout till the subgrid is loaded as subgrids are loaded asynchronously after the form is loaded. There was no way we can have a trigger on load of a subgrid till CRM 2015 Update 1. What we used to do is explained in older post here.

But with CRM 2015 update 1, we now have an option to execute scripts when data is loaded in subgrids. Because of which we are not required to have any timeout added in the script and iterate it till the data is loaded into subgrid.

With addition on GridControl.addOnLoad method, we can now add event handler for OnLoad event of subgrid which is more reliable than the form OnLoad event for form with a timeout. This event will get triggered whenever data is bound to a subgrid.

The steps to add this event is not similar to adding a form OnLoad event (from form customization popup), the way to add it is by invoking it using a code from other events (e.g. form OnLoad) by making use of GridControl.addOnLoad method. Similarly, use GridControl.removeOnLoad to remove event handlers.

Xrm.Page.getControl(“Contacts”).addOnLoad(myContactsGridOnloadFunction);

References:

https://msdn.microsoft.com/en-us/library/dn932137.aspx?f=255&MSPPError=-2147217396

https://msdn.microsoft.com/en-us/library/dn932126.aspx#BKMK_subgridAddOnLoad

https://crmcooking.wordpress.com/2015/07/15/writing-scripts-for-subgrids-with-crm-2015-update-1/

Advertisements

The new form rendering engine

***[Referencing to Microsoft Dynamics CRM Team Blog]

In Microsoft Dynamics CRM Online 2015 Update 1 (v7.1), a new form renderer was built to provide better performance. Forms will load significantly faster and more efficiently. The new renderer is based on previous generations and has the same functionality and behavior. However there are some things that admins and developers need to do to ensure full compatibility when upgrading.

What will users notice?

End users will not notice anything different, other than forms loading faster. The new form rendering engine has full support for client scripting (Write code for Microsoft Dynamics CRM forms), uses the same XML definition (Form XML schema), and has the same behaviors all around. There have been no fundamental changes made in terms of what the form does.

In order to help catch unsupported customizations, we added a dialog that displays the issue when script errors occur so that they do not fail silently. If these symptoms occur then it is likely there are unsupported customizations in the system.

What changed?

All the changes have been focused on how the form load process can be optimized. There are 2 main changes that have been made: loading process of the form, and handling of cache.

In terms of loading process, we have parallelized as many operations as possible to eliminate time wasted because the browser is idle. We increased the content that’s cached, moved rendering processes partially to server-side, and optimized the initialization of controls.

Form load used to be a very linear process. Since the new form renderer is more parallelized, the rendering engine now constructs the form and XRM model first and binds the data whenever the server responds. The diagram below is a rough approximation in order to illustrate the differences between the 2 rendering engines and may not reflect the exact changes.

Forms also used to waste a lot of resources. Since they were hosted in iframes, the iframe would be discarded and reloaded on each form load. The new form renderer does not discard iframes and instead keeps the iframe around. All common scripts are already parsed and never need to be loaded again. This introduced the design to load custom scripts and ISV scripts in a separate iframe which is the one that’s discarded when the form closes.  Previously, these scripts would be loaded in the same iframe as the form.

In summary:

  • Iframes are now kept throughout the user session
  • Custom scripts are loaded in separate iframes
  • No changes in supported scripts or form
    capabilities

What do I need to do?

As an admin or developer there are some things to be aware of. Because the new form rendering engine makes changes to how iframes are organized, any attempt to access unsupported APIs or use direct DOM manipulations may fail and need to be fixed.

Customers should all make sure to test their organization in sandbox mode to preview before upgrade. This way, should any symptoms show up around forms not loading/script errors, you will be able to catch and fix it
before upgrade.

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.

In order to help identify potential issues, the CRM 2015 custom code validator can be used. It’s primary purpose is to identify usage of deprecated APIs but it will also attempt to flag usage of unsupported APIs. The tool can be found here: https://www.microsoft.com/en-us/download/details.aspx?id=45535.  Developers should also review their scripts to ensure only supported APIs are being used.

Customers that have 3rd party solutions should reach out to their partners for updated solutions that have been verified to work with the new form rendering engine. While most are expected to continue to work, those with unsupported customizations need to be updated.

Fallback options

In case there is difficulty identifying the issue or a backup plan is needed post-upgrade, we have introduced an organizational-level fallback to temporarily allow usage of the legacy rendering engine. This will ensure compatibility at the cost of performance. Do not rely on this solution long term as the plan is to remove this option in the following release.

This setting can be found under Settings -> Administration -> System Settings -> General. Select “Yes” under “Use legacy form rendering” to enable this mode for all users.

If script errors are showing up, or if forms are not behaving as intended, this setting can be used to diagnose if the problem is specific to the new form rendering or not. If it is due to the new form rendering engine, then most likely there are some unsupported customizations.

If you are the owner of the scripts, make sure that there are no unsupported customizations. Otherwise reach out to the provider of the solutions for an updated solution.

View article…

Business Rules in CRM 2015 – What should one know?

I came across a new thing about Business Rules in CRM 2015 which I was not aware of. While working on JavaScript to hide a section OnChange of a field, I ran into an issue where the section was not getting hidden on change of field value. After few minutes of debug and then bit research, found that JavaScript runs before business rules. In my case, below was the scenario which caused the trouble:

I had two sections, A and B. One field “Record Type” from section “A” had Business Rule on it which hides a field “Field 1” which is in Section B. Then I had a JavaScript which triggers OnChange of “Record Type” field and hides “Section B”. As JavaScript triggers before Business Rule, JavaScript use to hide “Section B” after which Business Rule used to show the complete “Section B” again and hide only “Field 1” mentioned in business rule.

Below are few more things one should know about Business Rules in CRM 2015:

•    The rules need to be activated before they take effect (similar to workflows).

•    You can specify whether the rule applies to all forms or specific forms.

•    The rules fire in the new mobile client for iPad and Windows 8.

•    The rules are client-side rules, they do not fire during API calls, data import, etc. Microsoft’s vision is to add that support in a future release.

•    The rules do not support show/hide of Tabs and Sections. You either need to mention each field individually in your Business Rule or use JavaScript.

•    If your rule hides a field then CRM moves fields up to close the gap.

•    You need to consider the inverse of your rule i.e. in my example I tell CRM what to do when the Est. Revenue field contains data. I don’t tell it what to do when the Est. Revenue does not contain data. I need to write a second Business Rule for that.

•    JavaScript runs before Business Rules.

•    String comparisons are case sensitive.

Use of TypeScript in MS Dynamics CRM

Today I came through an interesting article about Typescript and its use in MS Dynamics CRM. TypeScript is a free and open source programming language developed and maintained by Microsoft.

It is a strict superset of JavaScript, and adds optional static typing and class-based object-oriented programming to the language.

https://crmbusiness.wordpress.com/2015/04/16/crm-2015-typescript-is-ready-to-go-definition-files-available-on-nuget/

It is an open source and a great tool to write JavaScript which would be easier to understand and with the intellisense would make less syntax, avoid typo errors and save time publishing JavaScript files. After having hands on experience, we can actually say that it is like writing an early bound code which is easy to understand, remove syntax errors and casting and type errors are found at compile time.

You can visit the below site to download and learn TypeScript:

http://www.typescriptlang.org/

Only update things you need to

While it is important not to reduce the benefit of a Dynamics CRM system by excluding activities that would be beneficial, often requests are made to include customization that add little business value but drive real technical complexity.

Consider a simple business scenario:

If every time we create a task we also update the user record with the number of tasks they currently have allocated, that could introduce a secondary level of blocking as the user record would also now be heavily contended. It would add another resource that each request may need to block and wait for, despite not necessarily being critical to the action. In that example, consider carefully whether storing the count of tasks against the user is important or if the count can be calculated on demand or stored elsewhere such as using hierarchy and rollup field capabilities in Dynamics CRM natively. Limited update philosophy should also be adopted while extending CRM using Processes, Plugins or Scripts.

 

 

This is something that reminds me of normalization in DBMS J

***References : Scalable Dynamics CRM Customization documentation

CRM 2015: Applying custom FetchXml to a subgrid using JavaScript

The implementation of applying custom FetchXml to a subgrid has appeared to have changed from CRM 2011 to CRM 2015. The change is with respect to GridControl.SetParameter() but I’m NOT referring to the issue of setParameter vs SetParameter which all know.
If I use Xrm.Page.getControl(“grid”).control.SetParameter(“fetchXML”,fetchxml) I get an error “Object doesn’t support property or method ‘SetParameter’“.
Trying setParameter for SetParameter yield the same result.

The issue here is object returned by Xrm.Page.getControl does not support setting the FetchXML of a sub-grid. Your use of getElementById is the only way to accomplish this goal, though it is not supported and technically could be broken by an update.

So the working version for CRM 2015 is as below:

document.getElementById(“grid”).control.SetParameter(“fetchXML”, fetchxml);

Also when you set up the subgrid with “Records = Only Related Records” in the Data Source section, the subgrid will append a condition to your fetchxml so that it returns only records related to the specific relationship that you specified. So always select the Records as all record types.

One more change with FetchXML is that previously if we want to get all records for a condition, we used to add “*” as a value for that condition. This has changed now, the “*” is now automatically converted to “%%%” while generating FETCHXML.

Sample code:

//Filter connection subgrid
function FilterConnectionSubgrid()
{

var ConnectionSubgrid =document.getElementById(“Contacts”);
if(ConnectionSubgrid==null)
{
setTimeout(function () { FilterConnectionSubgrid(); }, 2000); //if the grid hasn’t loaded run this again
return;
}
var fetchXml = “<your fetchxmlquery here>”

//Set the fetchxml directly to subgrid

ConnectionSubgrid.control.SetParameter(“fetchXml”, fetchXml); //set the fetch xml to the sub grid

ConnectionSubgrid.control.Refresh(); //refresh the sub grid using the new fetch xml
}

Hide “Business Process Flow” using JavaScript – (UNSUPPORTED)

Dynamics CRM 2013, BPFs have many beneficial qualities. They are available for out-of-the-box (OOB) and custom entities, can span across multiple entities, you can create multiple BPFs for a particular business process, can be role based, can be included in solutions for export and import, and work in the browser, Outlook Client and Tablets.

A key purpose of a BPF is to guide users through a specific business process to completion.

But there may be requirement where you are required to hide the Business Process Flow from the form depending on certain conditions. Unfortunately there is no supported way yet to achieve this. But you can always play with DOM structure using JavaScript to achieve this. Below are the line of code that you can use to show/hide BPF depending on conditions.

//Hide Business Process Flow

document.getElementById(‘header_process_d’).style.display = “none”;

//Show Business Process Flow

document.getElementById(‘header_process_d’).style.display = “block”;

Enable Web resource and Iframe support for Tablet in CRM 2015

Chitrarasan's Blog

MS CRM 2015 looks like going to support  web resources and Iframe in  tablet. Here is the settings where you can configure this.

Go to Settings->Administration->System Settings-> Customization Tab check the “Enable Web resources and Iframes for tablet”

It does says its preview feature only so if you come across any issue, Microsoft may not support.

2014-12-01_1136

View original post

Script Search Utility for Dynamics CRM 2011/2013

MSDYNAMICSBLOG BY DEEPESH

Script Search Utility for Dynamics CRM 2011/2013 addresses some of the following pain points while configuring, documenting and trying to resolve issues related to scripts in Dynamics CRM 2011 and Dynamics CRM 2013. Key features of this application are:

• For documentation purpose, Ability to search script files for specific text in script like unsupported scripts during CRM upgrade
• For documentation purpose, Ability to search scripts for attribute names in CRM scripts.

This tool also lets you copy search result to clipboard.

Download link: Click here

How to use :

Download the doc file, rename it to zip file, extract it and you are done.

For any issues/ bugs, you can connect me directly at –deepeshsomani@hotmail.com

clip_image002

This tool uses the Connection Control for Microsoft Dynamics CRM 2011 which is available at https://connectioncontrol.codeplex.com. I recommend using this tool for anyone who needs to connect to CRM instances be it…

View original post 14 more words

JavaScript methods do not trigger on update of business required fields to blank : CRM 2013 UR 3

Recently I came across a peculiar issue while running a java script on change of a mandatory (Business Required) field. JavaScript used to fire on update of perticular value but not if i change the value for the field to blank. Even debugger was not hit even though everything was correct.

On research came to know that this is a known issue and will be fixed by Update Rollup 3 for Microsoft Dynamics CRM 2013.

Below are more details on same:

http://support.microsoft.com/kb/2930480

issue