Plugin Development: Retrieve data using images

Images are useful for data comparison before and after core operation. We can register plugins on two type of images:

  • Pre-Image
  • Post-Image

Pre-Image can be used for retrieving the value of an entity attribute before core operation takes place.
Post-Image can be used for retrieving the value of an entity attribute after the core operation has taken place.

Scenario: On contact entity we have email address field. Let’s stop users from updating the email address field by showing them the old and new values.

using System;
using Microsoft.Xrm.Sdk;

namespace HelloPlugin
{
public class PreImagePlugin: IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

// Get a reference to the Organization service.
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];

try
{
//Implement Plugin Business Logic here
string newemailaddress = string.Empty;

if (entity.Attributes.Contains("emailaddress1"))
{
newemailaddress = entity.Attributes["emailaddress1"].ToString();
}

Entity preImageContact = (Entity)context.PreEntityImages["PreImage"]; //PreImage is user defined name you can name anything.

string oldemailaddr = preImageContact.Attributes["emailaddress1"].ToString(); //preImageContact will provide us the value which was saved before the update event.

throw new InvalidPluginExecutionException("The email address is modified from " + oldemailaddr + " to " + newemailaddress);
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
}
}
}

Below is the screenshot of the exception message thrown by our plugin:

Figure 1: Populating email address using pre-image

Plugin Development: Duplicate Check

Today we will learn how to restrict users from entering duplicate value in MS Dynamics CRM.

Let’s take as an example of Contact entity where we need to restrict users from entering duplicate email address which is already present in CRM while creating or updating a contact record.

I know there would a thought in your mind why don’t we use Duplicate Detection rule instead of plugin. So the answer to this question is duplicate detection rule will give user a warning message about the presence of duplicate record but still user will have the ability to ignore the warning message and save the record. Therefore, plugin is required for restricting users from entering duplicate records.

Note*: Below are the different techniques using which we can retrieve records. In this plugin we will be using Query Expression.

  • Fetch XML
  • Using Retrieve
  • Query Expression
  • Query By Attribute
  • LINQ
using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace HelloPlugin
{
public class DuplicateCheck: IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

// Get a reference to the Organization service.
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
//Obtain the target entity from the input parameter
Entity contact = (Entity)context.InputParameters["Target"];

try
{
//Implement Plugin Business Logic here
string email = string.Empty; //Variable declared to check whether emailaddress field is empty or not.

if (contact.Attributes.Contains("emailaddress1"))
{
email =  contact.Attributes["emailaddress1"].ToString();

QueryExpression query = new QueryExpression("contact");
query.ColumnSet = new ColumnSet(new string[] { "emailaddress1" });
query.Criteria.AddCondition("emailaddress1", ConditionOperator.Equal, email);

EntityCollection collection = service.RetrieveMultiple(query);

if (collection.Entities.Count > 0)  //Check if any record is present with duplicate email address
{
   throw new InvalidPluginExecutionException("Contact with email   already exist");
}
}
}
catch (Exception ex)
{
   throw new InvalidPluginExecutionException(ex.Message);
}
}
}
}
}

Points to Remember for registering the plugin. Add two steps one for create contact another for update contact.

  • Message = Create and Update
  • Primary Entity = contact
  • Pipeline Event = PreValidation

Hope this helps!!

Plugin Development: Create follow up task on create of Contact.

Create a follow up Task on create of Contact. The task should be completed in 2 days from the contact created on date.

Register the Plugin on:

  • Message = Create
  • Primary Entity = contact
  • Pipeline Event = PostOperation
using System;
using Microsoft.Xrm.Sdk;

namespace HelloPlugin
{ 
public class CreateTask: IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

// Get a reference to the Organization service.
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
//Obtain the target entity from the input parameter
Entity contact = (Entity)context.InputParameters["Target"];
try{
//Implement Plugin Business Logic inside try block
Entity taskRecord = new Entity("task");   //Creating object taskRecord of task entity.

//Single line of text(String fields)Append Follow Up on Task entity Subject field 
taskRecord.Attributes.Add("subject", "Follow Up"); 
//Append Need to follow up with contact statement on Task entity description field 
taskRecord.Attributes.Add("description", "Need to follow up with contact");   

//Set value in Date field
taskRecord.Attributes.Add("scheduledend", DateTime.Now.AddDays(2));  //Added 2 days from the Contact creation date.

//Set value in Optionset field (use Optionset value not lable) 
taskRecord.Attributes.Add("prioritycode", new OptionSetValue(2));  

//Set Parent Record to Task record.
//taskRecord.Attributes.Add("regardingobjectid", new EntityReference("contact", contact.Id)); //Old Methodology

taskRecord.Attributes.Add("regardingobjectid", contact.ToEntityReference());//New Methodology -- Link to Contact Record.

//Create a task record
Guid taskGuid = service.Create(taskRecord);
}

catch (Exception ex)
{
   throw new InvalidPluginExecutionException(ex.Message);
}
}
}
}
}
Figure 1: On create of Contact, follow up task got automatically created.

Security Role Issue with OfficeGraphDocument entity

Today I went through an issue where I had a custom security role (Business Admin) having almost the same privilege as system admin user expect the update permission on custom master entities.

Issue: When user having Business Admin role was trying to assign security roles to other users then suddenly a message popped up on screen as permission issue.

RoleService::VerifyCallerPrivileges failed. User: a52a0940-6fde-e811-a96a-000d3af05828, PrivilegeName: prvReadOfficeGraphDocument, PrivilegeId: 39016011-ae1a-41d1-9a22-a2611ad16702, Depth: Global, BusinessUnitId: be4a982d-8cd0-e811-a964-000d3af05df5 If you contact support, please provide the technical details.

Reading the above message it is clearly state that read privilege needs to be provided on OfficeGraphDocument entity. But The entity is not visible on the security role form therefore the system admin user cannot go ahead and provide the permission

While investigating on the issue I found that Office Graph integration for Dynamics 365 for Customer Engagement apps was deprecated on August 31, 2017, at the same time that Office ends GQL query support. Customers can continue to use Office Graph integration through August 31, 2017. After August 31 that date, the Office Graph trending documents component will cease to function, and you’ll see the following error message:

We can’t get to the trending documents. Try again later.

Refer Microsoft site for more details: Click Here

Assuming you people are aware about XRMToolBox and establishing connection with Dynamic CRM Organization.

Resolution: Use XRMToolBox, connect the tool with the organization. Search for Role Updater plugin as shown below:

Figure 1: XRM ToolBox – Plugin Role Updater

Click on Role Updater and hit Load Roles and Privileges button. This will load all the entities and the privilege which are assigned on that entity.

Figure 2:Click Load Roles and Privileges button

Enter OfficeGraphDocument entity under Search box.

Figure 3: Enter OfficeGraphDocument

The below screen appeared with the privilege which OfficeGraphDocument entity had.

Figure 4: OfficeGraphDocument entity privilege visible (Read privilege can be set to access level as Organization or None.)

Select Read and

Step 1: Hit the organization button

Step 2: You will see that entity OfficeGraphDocument has beenprovidedOrganization level access on PrivilegeName: prvReadOfficeGraphDocument.

Step 3: Hit Next button to take effect in the connect organization.

Figure 5: Read privilege has been provided Organization level access.

Performing these steps resolved the issue.

Now, user having Business Admin security role was able to provide other users their desired security role excluding System Admin role.

Hope this blog helps anyone!!!

MS Teams integration with Dynamics CRM

MS Dynamics CRM and MS Team integration provide users the ability to pin up records/views which are most frequently used by the user.

We need to create a Team for achieving the above functionality.

Figure 1: Created Team

New team has been created now. Let’s name it as MS Dynamics and Team Integration. We need to click on (+) icon. To pin a record or view.

Figure 2: Use Plus (+) Icon to Pin Record

Search for Dynamics 365.

Figure 3: Search Dynamics 365

Click on Entity Selection –> Filter Entity for fast search (highlighted in blue) –> Enter the record name. Select the record and hit Save button.

Figure 4: Search Entity Record using filter

The selected record has been pinned on Team now.

Figure 5: Pinned Account Entity record

We need to follow the same steps to pin a View on Teams. Select the entity view and click Save button.

Figure 6: Search Account Entity View
Figure 7: Pinned Account Entity view (My Active Accounts)

When Microsoft Teams Integration is enabled, to get the Collaborate button appears on records in Dynamics 365 for Customer Engagement apps. We need to Enable Dynamics 365 and Teams Integration from System Settings.

Login to Dynamics CRM:

  • Go to Settings > Administration > System Settings > General tab
  • Enable Microsoft Teams Integration
Figure 8: Enable Microsoft Teams Integration – Collaborate button

Hope this blog help!!

MS Teams integration with Dynamics CRM

Today we will learn how to integrate Dynamics CRM with MS Teams.

Open Teams –> Go to Apps –> Search Dynamics

Figure 1: Login Team App
Figure 2: Search for Dynamics 365 App

Select the Dynamics 365 App, below screen would appear. We need to click on the Install button.

Figure 3: Install Dynamics 365 App

Select App

Figure 4: Open Dynamics 365 App

Select the CRM Environment and Dynamics 365 app for establishing connection with MS Team.

Figure 5: Select CRM Org. to configure with MS Teams
Figure 6: Selected CRM Org. Hexaware and Sales Hub App.

The below screen will appear after clicking Save Changes button.

Figure 7: CRM Dashboard in Teams

Teams provide us the ability to select CRM records and work on it having the same user experience as Dynamics CRM.

Figure 8: Access CRM record from MS Teams

Now, clicking on the Conversation tab and hit Configure button for using Teams Bot functionality.

Figure 9: Configure MS Teams Bot

Select the CRM Environment and hit Save button.

Figure 10: Select CRM Org.

Commands which can be currently used in Teams.

  • Search
  • Show
  • Change environment
  • Change App
  • Help
Figure 11: MS Teams Bot Commands

I entered show Hitachi Account.

Figure 12: Record fetch using MS Teams bot functionality

Next Session we will learn how to pin up CRM records on MS Teams. Click Here

Retrieve Deleted Record From Dynamics CRM

Today we will learn how to retrieve and restore deleted record from Dynamics CRM without programming.

For this we need to have XRMToolbox.

Open XRM Toolbox go to Plugin Store and navigate to Search.

Figure 1: XRMToolBox Plugin Store

Enter Recycle Bin in the Search box. Install the plugin by selecting the checkbox and hit Install button.

Figure 2: Search Plugin – Recycle Bin

Once the Recycle Bin plugin is successfully installed. Go to Plugins and search Recycle Bin.

Figure 3: Search Installed Plugin Recycle Bin

Connect to the Dynamics CRM Organization and select Recycle Bin Plugin.

Below screen will appear.

Figure 4: Plugin Recycle Bin Page

Hit the Load Entities and Users button. This will load all the Entities and Users of the connected CRM Instance.

Figure 5: Click Load Entities and Users

We need to select the Entity, User and the date range from which we need to retrieve the deleted record.

Note: Entity for which Auditing is enabled will only show under Select Entity dropdown.

Now to test the tool, I have deleted a record from Contact entity.

Figure 6: Deleted Contact Thomas Cobley

Going back to XRMToolbox select entity as Contact and hit Show Deleted Records.

We will get the all the deleted records against the user selected in the Select User field.

Note: If All Users value is selected under Select User field then the tool will provide us all the records deleted by any users.

Figure 7: Retrieve all the deleted records

Select the record which we would like to restore back into CRM. By selecting the record and clicking on Restore Records button as shown below.

Figure 8: Restore the deleted records

Hope this blog helps you!!!

Gamification with Dynamics CRM 365

Today we will learn how to install and setup gamification in Dynamics CRM 365.

Login to Microsoft App Source and search for Microsoft Dynamics 365 – Gamification.

Figure 1: Login to Microsoft App Source

Click on Get it Now, below screen will appear.

Click both the check boxes – Agreeing on Microsoft Legal Terms and Privacy Statement. Hit Agree button.

Figure 2: Accept Microsoft terms and condition

Below screen will appear click on INSTANCES tab search for Gamification and install it. The installation would take few minutes.

Figure 3: Search Gamification
Figure 4: Install Gamification

After gamification solution has been successfully installed.

Navigate to Dynamics CRM 365 go to Settings –> Solutions. Here we will find solutions related to gamification.

Figure 5: Gamification Solution

We can now find the Gamification module. Click on Gamification Settings.

Figure 6: Gamification Module in CRM

Clicking on Start Activation button will ask to provide the permission for gamification.dynamics to accept you organization.

Figure 7: Activate Gamification
Figure 8: Authentication required for activating gamification

Click on Activate button, generate the security key.

Figure 9: Activate Security Key

Copy the security key and paste it in below Security Key text box. Click Activate

Figure 10: Paste Security Code in Security Key
Figure 11: Successfully Installed Microsoft Dynamics 365 – Gamification

Clicking on continue will take you to the below Gamification Portal

Figure 12: Gamification Portal

Else Go to Dynamics 365 CRM — Gamification –> Gamification Settings. Click Open Gamification Portal

Figure 13: Will open Gamification Portal

Click on Games –> Game Setup

Figure 14: Start Game Setup

Below screen will appear. Provide the details in the below fields:

Name                 –>      Game Title

Game Model     –>      Individual or Team Game

Start Date            –>      Game Start Date

End Date              –>       Game End Date

Figure 15: Game Setup

Moving to the next stage create KPI. Assign point for every user action as shown in the below screenshot.

Example: If a user create Lead in CRM for every Lead user will get 10 points.

If a user create opportunity in CRM for every opportunity user will get 50 points.

Figure 16: Define Score Point

Select the players for the game.

Figure 17: Select Player

Select Fan for the game who would be support the player.

Figure 18: Select Fan for the Game

Declare the reward price for the players who come 1st, 2nd or 3rd in the game.

Click Start Game button.

Figure 19: Declare Price Amount and Start Game
Figure 20: Game Successfully Setup

Go to Games and hit the Games link:

Figure 21: Games

Click on Saved Games tab, select the same and activate it.

Figure 22: Activate Games

After the games is activated. We will get a notification stating that the games have been activated.

Figure 23: Game Activated Successfully

Let’s create some lead and opportunity within CRM. To check how the score point raising within the Score Board game.

Figure 24: Score Board

To check the Lead Score points, click on the KPI Award dropdown. Select Leads Created Award option.

Figure 25: Check Lead Score Point
Figure 26: Lead Creation action score board

Click on Opportunity Created Award.

Figure 27: Opportunity Creation action score board

Happy Gamification!!

Gamification with Dynamics CRM 365

What is Gamification?

Gamification is a part of Microsoft Dynamics 365 launch. It helps the organizations to calculate their employee performance matrix into a game.

Gamification uses the principle from fantasy sports. Which create a game like experience inside the Microsoft Dynamics CRM. Bringing gamification into dynamics is designed to bring greater competition and get the user experience more fun.

Why Gamification?

Gamification has multiple sports inside its solution. Which calculate points based on the action which a user performs within CRM.

While implementing gamification if we apply more gaming principle and make the whole process more fun it may motivate users to come inside CRM and be consistent in entering data.

Note*: In short Gamification is more helpful in boosting your team productivity and Dynamics 365 user adoption.

It is a solution in dynamics 365 which allows user to participate individually or team-based game.

Security Roles in Gamification

Commissioner: Can act as an admin for all the games which are within the CRM. But can not participate in any games nor score any point.

Note*: Game commissioner has a right to create new game and mange users within Gamification portal.

Game Manager: Can help commissioner in performing some administer task. But can participate in games and score points and win awards.

User: Can score point by performing action and achieving result as per defined KPI and win awards.

Fan: Can pick his own team and follow teams.

Using Scanner in MS Dynamics 365

Microsoft Dynamics 365 CRM comes with many functionalities. One of the interesting functionalities is reading Barcode from mobile and tablet.

Let’s implement and check this out.

Create a custom field of type “Single line of Text”.

Figure 1: Create Custom Field

Place the field on the form. Select it and click on Change Properties button on the Home tab.

Figure 2: Place the custom field on Form

Below screen will appear you need to go to Controls tab and click on Add Control link.

Figure 3: Option for adding BarCode
Figure 4: Select option as Barcode Scanner

Now, select option as Phone and Tab. This is a mobile functionality. Click OK and Publish the Form for reflecting the changes across the Organisation.

Figure 5: Select Option as Phone and Tablet

Login CRM using D365 mobile app and open a record. Click on the scanner icon which appear next to the Scanner field. This will turn on your mobile camera and you will be able to scan the bar code of your product.

Figure 6: Option for scanning the Barcode

Scanning the Barcode. When the scan gets completed successfully the code associated to it will auto populate inside the Scanner field.

Figure 7: Scanning the Barcode.
Figure 8: Barcode value got populated inside the Scanner field.

Note: The value inside the Scanner field will be visible from Web form as well.

Design a site like this with WordPress.com
Get started