Dynamics CRM Creating and Debugging JavaScript Code

One of the benefits of using Dynamics CRM is the ability to write client side JavaScript code to perform actions on the user interface. Let’s go through an example of how to do this. In this example, we will show a message box when a user changes a value on a field. We will do this on the Website field on the Accounts form: Firstly, edit the Accounts form to display the developer view: … Continue reading Dynamics CRM Creating and Debugging JavaScript Code

Node.js Hello World on Windows

In this example, we will create a Hello World application for Node.js. Let’s start with a simple example. I have installed Node.js on Windows and have a Node directory in C:\ drive. In command prompt, cd to this directory. In that directory is a JavaScript file that writes out a console log “Hello World”: To run the file, enter: node HelloWorld.js Hello World is returned by Node. Now create a new … Continue reading Node.js Hello World on Windows

D3 Hello World

To create a D3 “Hello World”, do the following. Go to the d3js.org website and find the latest D3 version: Copy the link to the latest release: <script src=”https://d3js.org/d3.v4.min.js”></script> Create an HTML page and add the following code, with the link above: <!DOCTYPE html> <meta charset=”utf-8″> <body> <script src=”https://d3js.org/d3.v4.min.js”></script> <script> d3.select(“body”).append(“span”) .text(“Hello world”); </script> Run the page:  

Dynamics 365 $ is not defined

In your JavaScript code, you may receive this error when running jQuery code: $ is not defined To resolve this, add the following code to JavaScript before the jQuery call is made: if (typeof($) === ‘undefined’) { $ = parent.$; jQuery = parent.jQuery; }

JavaScript Console.Log Hello World

Console.Log allows for developers to write log events to certain web browsers. Here we will do a Hello World example using Chrome. First, create a new html document, and add the code: Open the document in Chrome and select F12 to open the developer tools. Go to the Console tab. You will now see the output: This logging can be useful in troubleshooting code. You can additionally write commands directly … Continue reading JavaScript Console.Log Hello World

Classes in JavaScript

There are different ways to define classes in JavaScript. Let’s look at some examples. Let’s say you want to define a class for a Customer. The customer contains attributes such as: First Name Last Name Email Phone Number The Customer class also contains methods such as GetCustomer to get the customer information. Create a new file with the extension .html, e.g. JSClasses.html. Add <script> tags. These will be our placeholders … Continue reading Classes in JavaScript

Dynamics CRM JavaScript OnSave and OnLoad

In Dynamics CRM, you have the ability to hook onto the OnLoad and OnSave events of an entity. We will go through a simple example. Open the entity in Customizations. Let’s do this with Accounts. Go to Form Properties: Under UI Events, you will see the two options for OnLoad and OnSave. Let’s start with adding a new JavaScript library. Select Add: And then New: Enter a name and select JScript: … Continue reading Dynamics CRM JavaScript OnSave and OnLoad

Namespaces in JavaScript

Namespaces are used to help organize code into logical groups. An example of a namespace is MyCo.ERP.Customers, which may contain code regarding ERP Customers. I could also have a namespace called MyCo.CRM.Customers. When writing an app, I can reference each piece of code using their fully qualified name to avoid confusion of what methods I would like to run. In languages like C#, namespaces are easily implemented. In JavaScript, we can … Continue reading Namespaces in JavaScript