28/05/2019

How to add a button in D365 using Ribbon Workbench

We are going to add/create a custom button on an entity in D365 using ribbon workbench solution.

Scenario: On click of a button, we are going to generate a GUID and update that value in a field.

Prerequisites:

1. Ribbon Workbench solution (can be downloaded from the above URL)
2. Create a custom entity (in this post, we have created an entity called "Requests")
3. Create a solution and add the above entity to it
4. Create a web resource (JScript) to generate a GUID

How To?

1. Log into D365, Go to SETTINGS -> Solutions -> Click on "RIBBON WORKBENCH 2016"
2. Select a solution from the available list ("My Solution" in our post)
3. Select the BUTTON on the left side ribbon. Drag and place it on the Main Form as shown in the below image
4. Click on the + button next to COMMANDS(1) as shown below and change the Id to "new.new_request.generatekey.Command". Changing the Id value is not mandatory, its just for our convenience

a. Now click on "+ Add Action" and select "JavaScript Action"
b. Select respective Web Resource from the "Library" lookup and add the function name in "Function Name" field
Eg: Library:              $webresource:new_uniqueid.js
       Function Name: buttonGenerateKey

Click on "Add Parameter" and select "CRM Parameter". Choose "PrimaryControl" from the drop-down.



Note: This parameter helps us to get execution context on on button click

5. Now click on on the BUTTONS(1) and select the above command that we have created. Update the button labels and other fields as shown in the below image

6. Publish all the changes
7. Go to Requests entity and click on New and fill the required data. Click on "Generate Key" button. There we go, an unique key which is generated is updated in the field


Here is the sample code that's used in the post


function buttonGenerateKey(primaryControl)
{
    var formContext = primaryControl;
    var uniqueNumber = this.generateUniqueKey();
    if (uniqueNumber != null)
    {
        formContext.getAttribute("new_requestkey").setValue(uniqueNumber);
    }
    else return;
};
function generateUniqueKey()
{
    var d = new Date().getTime();
    if (Date.now)
    {
            d = Date.now();
    }
    var uniqueID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c)
    {
            var r = (d + Math.random() * 16) % 16 | 0;
            d = Math.floor(d / 16);
            return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
    });
    return uniqueID;
}

02/02/2019

Sample console application to connect MS CRM / D365

Here is a sample console application, to get connected with MS CRM / D365
Make sure, you are using .Net 4.6 framework. In case you are using .Net Framework below 4.6, please uncomment ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; in the below code. The main purpose of this to provide more secure connectivity to the application, in which we have Microsoft updated and industry standard security policies.

For more information on this, please refer here

Steps:

1. Open Visual Studio, click on New Project
2. Select Visual C# and chose Console Application in the right pane.
3. Chose a desired name and location to the application
4. Go to Tools -> NuGet Package Manager -> Package Manager Console
5. In the console window, paste this - Install-Package Microsoft.CrmSdk.CoreTools -Version 9.0.2.6

Earlier, we used to add all the required CRM dlls from CRM SDK, now this the above NuGet package is taking care of that and it contains official SDK tools authorized by Microsoft.

Code:


using System;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;

namespace CRMConsoleApp
{
    /// <summary>
    /// Program Class
    /// </summary>
    public class Program
    {
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            IOrganizationService organizationService = ConnectCRM();
            if (organizationService != null)
            {
                Guid currentUserGuid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;
                if (currentUserGuid != Guid.Empty)
                {
                    Console.WriteLine("User GUID: " + currentUserGuid.ToString());
                }
            }
        }
        /// <summary>
        /// Connecting to CRM
        /// </summary>
        /// <returns>IOrganization Service</returns>
        public static IOrganizationService ConnectCRM()
        {
            IOrganizationService organizationService = null;
            String username = "******@******.onmicrosoft.com";
            String password = "******";
            try
            {
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.UserName.UserName = username;
                clientCredentials.UserName.Password = password;
                //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                organizationService = (IOrganizationService) new OrganizationServiceProxy(new Uri("https://******.crm.dynamics.com/XRMServices/2011/Organization.svc"), null, clientCredentials, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception caught - " + ex.Message);
                Console.ReadLine();
            }
            return organizationService;
        }
    }

}

27/10/2017

Dependent Lookup in MS CRM 2016 and D365

Dependent Lookup in MS CRM 2016 and D365

Requirement: When a value selected in a lookup, related records for that lookup should be filtered in another lookup.

Eg: let’s say, we have Out Of SLA Reason and Out Of SLA Sub Reason lookup (entities). When a value is selected from Out Of SLA Reason Lookup, only related records of that value should be visible in Out Of SLA Sub Reason lookup.

Implementation:

  • Create two custom Entities – Out Of SLA Reason and Out Of SLA Sub Reason
  • Create a 1: N relationship (Referential) in Out Of SLA Reason with Out Of SLA Sub Reason. Which creates a lookup of Out Of SLA Reason in Out Of SLA Sub Reason entity.
  • Now go to Out Of SLA Sub Reason form and Out Of SLA Reason lookup on the form.



  • Now populate the data in Out Of SLA Reason and Out Of SLA Sub Reason.
  • Once data populated, go to Out Of SLA Sub Reason and select the related SLA Reason records from lookup for Out Of SLA Sub Reason records.
  • Now go to SLA Reason, SLA Sub Reason entities and create 1: N relationship (referential) to related entities.
  • Eg: If we want to show these lookup on Case. Create 1: N relationship (referential) from Out Of SLA Reason and Out of SLA Sub Reasons to Case entity. Which creates two lookup on Case entity.
  • Open case form and add these two lookup on the form.
  • Open Field Properties of Out Of SLA Sub Reason lookup from case form and go to Related Records Filtering section. Click on Only Show records where, choose Out Of SLA Reason (cases) and in contains Out of SLA Reason (Out Of SLA Sub Reason).

Now, when we click on Out Of SLA Reason and selects a record, only related records of that will show on Out Of SLA Sub Reason.


31/05/2016

We have been trying to update the blog with all the MS CRM information ....
Enjoy our MS CRM blog, please do leave feedback in the comments.

08/05/2016

CRM Intro

What is CRM?

CRM stands for Customer Relationship Management is to supervise and maintain customer relations effectively along with customer data, engagement and sales. So, CRM applications helps to organize and track the customer data effectively, from all in one place.

What is MS Dynamics CRM?

MS Dynamics CRM is an application helps you track all the customer interactions and data. With this application you can easily share all this information across your organization and can give clear picture to your teams through multiple channels. Heart of the Business Success is maintaining good relationship with your Customers.
Why MS Dynamics CRM?
MS Dynamics CRM is unique in the CRM marketplace due to
  • Look and feel of the application is very familiar and comfortable to work with
  • Comes with 3 Deployment options: On-Premise, Online, Hybrid.
  • Out of the box separate modules for Sales, Marketing and Service management which can be easily configurable as well as customizable
  • Ability to work with multiple business units
  • Defines and manage the information and interactions between the relationships
  • Easily integrates with MS Office
  • It works completely form within outlook to manage customer information, email messaging and calendar scheduling.
  • Operates with the .Net framework to customize the things and to meet the most advanced integration needs for 3rd party software.
  • Provides multi-currency and multi-language support which is available in over 80+ countries and 40+ languages.

MS CRM Goals:

The main idea of CRM is, that helps business using technology and human resources to have an insight of Customers and to gain business. With effective strategy we can increase revenue by...
  • What exactly the customer is interested in
  • Cross selling products
  • Retaining existing customers and discovering new ones. 
  • Attracting the customers with discounts and offers.
  • Providing best customer service. 


*****We have been trying to update the blog with all the MS CRM information ....Enjoy our MS CRM blog, please do leave feedback in the comments section.*****