Dynamics 365 addOnSave JavaScript method

The addOnSave method is used to add a function to the OnSave event. Let’s go through an example of how this is used. First we will define a new JavaScript function on the Account form. Open the Account form in Customizations and click to add a new Form Library: Select New: We will call this TestFunctions. Click Next: Create a new function. We will create a function to display the … Continue reading Dynamics 365 addOnSave JavaScript method

Dynamics 365 Sales Territories

Sales territories can be configured in Dynamics 365. To do this, go to Settings->Business Management: Select Sales Territories: Selecting a Sales Territory, we can see the name and members: Let’s create a new territory: And add members: Territories can be assigned to price lists: And Accounts (drag field onto the form):  

Dynamics 365 Fiscal Year Settings

In Dynamics 365, you can configure fiscal years. To do this, go to Business Management and select Fiscal Year Settings: From here, you can set up the start date, the template and display settings:    

Connecting Power BI Desktop to Dynamics CRM Online

To connect Power BI Desktop to Dynamics CRM Online, open Power BI desktop click on Get Data: Filter by Dynamics and select “Dynamics CRM Online”: Enter your OData URL and click OK. This will be in the format: https://*****.crm.dynamics.com/XRMServices/2011/OrganizationData.svc Select Organization Account and Sign In: Then click Connect from the same screen. This will load the entities from CRM.    

Deploy Security Roles Dynamics 365

There are situations where you create security roles in one organization and you need to transfer them to another organization, e.g. a development environment to a production environment. We will go through an example of how to do this. First, create a new security role: Next, add some permissions: Create a new solution and select the new security role: Now, in the destination system, select the security role: The new security role … Continue reading Deploy Security Roles Dynamics 365

Create Record in Dynamics 365 using jQuery

To create a new record of an entity in Dynamics 365, use the code below: var account = {}; account.Name = “Sample Account”; var jsonAccount = window.JSON.stringify(account); if (typeof($) === ‘undefined’) { $ = parent.$; jQuery = parent.jQuery; } $.ajax({ type: “POST”, contentType: “application/json; charset=utf-8”, datatype: “json”, url: Xrm.Page.context.getClientUrl() + “/XRMServices/2011/OrganizationData.svc/AccountSet”, data: jsonAccount, beforeSend: function (XMLHttpRequest) { //Specifying this header ensures that the results will be returned as JSON. XMLHttpRequest.setRequestHeader(“Accept”, … Continue reading Create Record in Dynamics 365 using jQuery

Query Dynamics 365 using jQuery

You can query Dynamics 365 data by using jQuery. Here we will go through an example. We will be connecting to the OData Web service. The URL will be: https://yourcrm.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/ To access the AccountSet data, the URL will be: https://yourcrm.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/AccountSet We can pass parameters to the OData to filter the data if required. Add the following JavaScript code to somewhere in CRM. This will retrieve all accounts using jQuery and display … Continue reading Query Dynamics 365 using jQuery

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; }

Dynamics 365 Accessing the Plugin Trace Log

The Dynamics 365 Plugin Trace Log settings are located in Settings->Administration->System Settings: And then accessed under the Settings->Customization menu: Records will be created here: And you can drill into each record for more details: Click here to learn how to write to the Plugin Trace Log from your plugins.

Dynamics 365 Raise Error in Plugin

To raise an error in the plugin code, we use InvalidPluginExecutionException. For example: throw new InvalidPluginExecutionException(“Plugin has run. Code will stop executing.”); The code runs in the Execute function of the plugin code. For example: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; namespace Carl.AssociateDisassociate {     public class AssociateDisassociate : IPlugin     {         public void Execute(IServiceProvider serviceProvider)         {             throw new InvalidPluginExecutionException(“Plugin has run. Code will stop executing.”);         }     } } The code will display the error and stop executing: If you register the code on the Pre-Operation it will prevent the rest of the CRM code from … Continue reading Dynamics 365 Raise Error in Plugin