Solving JQuery Issues in Microsoft Dynamics CRM Online 2015
With Microsoft Dynamics CRM Online 2015 Update 1, form scripts run in a different scope than the jQuery instance used by the application, hence, if you are expecting a JQuery instance in your
form script, you will no longer get one, thus, the call to the jQuery $.ajax method will fail with an error “$ is undefined”
You would normally use jQuery on a CRM form for 2 reasons: manipulate the DOM, or make AJAX calls. Since DOM manipulation is not supported, you would really only need jQuery if you were making AJAX calls. You can avoid using jQuery to make AJAX calls by using the alternatives as described below:
- If you must use Jquery on a form, you can perform the following steps:
- Add jQuery library to the form properties
- Create a new alias to access jQuery instead of $. (e.g., $xyz)
- Declare the alias with jQuery.noConflict()
- An example of what this would look like is var $xyz = jQuery.noConflict();
- From this point on you can make Jquery calls using $xyz.ajax() within your code
- If you’re not using a third party tool or the SDK, you can directly use the XMLHTTPRequest object for AJAX calls. Third party tools and the SDK are just wrappers around this object anyway.
- We recommend using the XRMToolKit library instead, as this library uses the XMLHTTPRequest object, and also provides common functionality for accessing CRM
- Note: XRMToolKit has methods that use Jquery, however these methods are in the “Extensions” namespace, and are “unsupported” as also declared in the toolkit
If you have other jQuery issues, please tell us what you encountered (and if/how you solved it) in the comments below. We may even use your feedback for a future blog post on this subject!
Written by Tunc Samiloglu
Principal Consultant/Architect, mcaConnect