How do I become a Dynamics 365 developer? ***Series update*** and Javacript Development

How do I become a Dynamics 365 developer? ***Series update*** and Javacript Development

Hi all!!!

I want to let you know that I am removing the max limitation on the series of articles titled : "How do I become a Dynamics 365 Developer?".

The intent here is continue writing on the topic as new features and sub topics become available.

Following the series, we will talk about javascript automation using the XRM client library. On this article you find explanation on the main JS functions, as well as counter part implementations of the same functionality using Dynamics CRM Business rules, where possible.

Microsoft Dynamics 365 (online & on-premises) provide many opportunities to use JavaScript. All JavaScript used in Microsoft Dynamics 365 is added by creating JavaScript web resources. This topic has information for developers who use JavaScript and includes links to relevant topics in the Microsoft Dynamics 365 SDK and other sources.

Areas where you can use JavaScript in Microsoft Dynamics 365

You can use JavaScript to perform actions in form scripts, command bar (ribbon) commands, and web resources.

Form scripts

The most common use of JavaScript in Microsoft Dynamics 365 is to add functions as event handlers for entity form events. For more information, see Write code for Microsoft Dynamics 365 forms.

Command bar (ribbon) commands

When you customize the Microsoft Dynamics 365 command bar, you can configure commands for controls that you add. These commands contain rules that control whether the control is enabled and what action is performed when the control is used. For more information, see Customize commands and the ribbon.

Web resources

Microsoft Dynamics 365 provides an organization-owned entity that stores a binary representation of a file that can be accessed by using a URL. This file is called a web resource. There are several types of web resources. A web resource that represents a JavaScript library is called a JavaScript web resource. You can use a webpage (HTML) web resource to provide a user interface with JavaScript libraries included just as you would for files on a web server. Because these files are part of Microsoft Dynamics 365, users who access them are already authenticated. Therefore, you can use Microsoft Dynamics 365 web services without having to write code to authenticate the user. For more information, see Web resources for Microsoft Dynamics 365 and Work with Dynamics 365 data using web resources.

Use of jQuery

Use jQuery with HTML web resources

We recommend that you use jQuery together with HTML web resources to provide user interfaces because it is an excellent cross-browser library.

With HTML web resources, you control the libraries that are present and there is no restriction against manipulating the DOM. Feel free to use jQuery within your HTML Web resources.

Avoid using jQuery with form scripts or ribbon commands

We do not recommend using jQuery in form scripts and ribbon commands.

Most of the benefit provided by jQuery is that it allows for easy cross-browser manipulation of the DOM. This is explicitly unsupported within form scripts and ribbon commands. Restrict your scripts to use the Xrm.Page and Xrm.Utility libraries available in form scripts and ribbon commands. If you decide to use the remaining capabilities of jQuery that are useful with Microsoft Dynamics 365 and include the ability to use $.ajax, consider the following:

  • For best performance, don’t load jQuery in the page if you do not need it
  • Using $.ajax to perform requests against the Microsoft Dynamics 365 web services is supported, but there are alternatives. The alternative to using $.ajax is to use the browsers XMLHttpRequest object directly. The jQuery $.ajax method is just a wrapper for this object. If you use the native XMLHttpRequest object directly, you do not need to load jQuery.
  • Each version of jQuery that is loaded in a page can be a different version. Different versions of jQuery have different behaviors and these can cause problems when multiple versions of jQuery are loaded on the same page. There is a technique to mitigate this, but it depends on editing the jQuery library and any other libraries that depend on jQuery. More information: jQuery and jQuery UI with Dynamics CRM 2011 & 2013jQuery.noConflict()

Debugging JavaScript in Microsoft Dynamics 365

Each browser provides some kind of debugging extension. Internet Explorer provides developer tools you can use to debug scripts in Microsoft Dynamics 365. The Internet Explorer developer tools can be opened by pressing F12 when viewing a page using Internet Explorer. For more information, see Using the F12 developer tools.

For Google Chrome, press F12 to open developer tools. Firebug is a popular browser extension for web development using Mozilla Firefox. For Apple Safari, you must first select the Show Develop menu in menu bar in Advanced Preferences. Then you can select Show Web Inspector from the Develop menu.

You can also use Microsoft Visual Studio. For more information, see How to Debug JScript in Microsoft Dynamics CRM 2011.

When you use JavaScript libraries in Microsoft Dynamics 365, your libraries are loaded with the web page. It can sometimes be difficult to isolate your specific library in the debugging environment. When using debugging tools in Microsoft Edge, on the Debugger tab, click on the folder icon at the top-left corner, and expand the available scripts and find the one with the name that corresponds to the name of your JavaScript web resource, such as the new_myCustomJavaScript.js web resource shown below. You can also search for your JavaScript library by typing the file name in the search box.

Dynamics 365 Javascript samples - Form scripts

//Set Control visibility
Xrm.Page.getControl("field_name").setVisible(false);

//Set Attribute Value
Xrm.Page.getAttribute("field_name").setValue(1.00);
 
  
//Disable Fields
Xrm.Page.getControl("field_name").setDisabled(true);

//Make field required
Xrm.Page.getAttribute("field_name").setRequiredLevel(true);
//Change set custom query results to look up fields
var customer= Xrm.Page.getAttribute("customers").getValue();
if (customer!= null) 
{
   fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
     + "<entity name='serviceappointment'>"
          +"<attribute name='customers' />"
          +"<filter type='and'>"
            +"<condition attribute='regardingobjectid' operator='eq' value='" + customer + "'  />"
          +"</filter>"
          +"<link-entity name='contract' from='contractid' to= 'new_contrat'>"
            +"<filter type='and'>"
             +" <condition attribute='customerid' operator='eq' value='" + customer + "' />"
            +"</filter>"
         +" </link-entity>"
       +"</entity>"
     +"</fetch>";
  
  
    Xrm.Page.getControl("new_contrat").addCustomFilter(fetchXml);    
}
 
  

Dynamics Business Rules

You can create business rules and recommendations to apply form logic without writing JavaScript code or creating plug-ins. Business rules provide a simple interface to implement and maintain fast-changing and commonly used rules. They can be applied to Main and Quick Create forms, and they work in Microsoft Dynamics 365 for tablets and Dynamics 365 for Outlook (online or offline mode).

By combining conditions and actions, you can do any of the following with business rules: Set field values, Clear field values, Set field requirement levels, Show or hide fields, Enable or disable fields, Validate data and show error messages, Create business recommendations based on business intelligence.


View details following the link below:


EasyRepro - Automated UI testing API for Dynamics 365

EasyRepro API's provide an easy to use set of commands that make setting up UI testing quick and easy. The functionality provided covers the core CRM commands that end users would perform on a typical workday and working to extend that coverage to more functionality.

EasyRepro uses Selenium framework under the hood. If you are familiar with Selenium you would be comfortable using the EasyRepro APIs.



要查看或添加评论,请登录

社区洞察

其他会员也浏览了