Is Gamification in a Microsoft Dynamics CRM a gimic?

To answer the question in the title, Microsoft certainly doesn’t think so because they have just acquired FantasySalesTeam.

Microsoft Acquires FantasySalesTeam, an Innovative Sales Gamification Platform, to Help Organizations Increase Productivity

CRM Gamified were the first company I had heard of using CRM and gamification and have an excellently sounding add on

Motivation Engine

CRM Gamified have a section on why gamification works, the three key principles, which you can see here

  • MOTIVATIONAL INTRINSIC PSYCHOLOGICAL FACTORS
  • DIFFERENT RESULTS ARE ACHIEVED BY CHANGING HABITS
  • KPIS DO NOT CHANGE JUST BY LOOKING THEM OVER

I will warn you this blog post is the Hosk thinking out loud, it doesn’t really go anyway but I thought I would share my thoughts on the subject.  I will add I haven’t used a gamification system yet but there usage is on the rise so maybe it’s a matter of time.

Core CRM

When I think of the core concept of CRM

Customer

Relationship

Management

It strikes me as feeling a bit old fashioned and slow moving when you consider the fast paced world of social media, twitter, instant messaging, the OMNI channel.

some of the benefits of a CRM system is having one source of data which multiples teams and individuals in an organization can use and leverage to effectively do their jobs.

CRM system give workers access to knowledge which can often be tucked away in individuals computers/heads/folders/documents.

CRM system can automate procedures

CRM systems can unify lots of desperate excel spreadsheets, bespoke software, different software all under one new CRM system.

CRM systems are

  • Information
  • People
  • Processes

What is gamification?

Here is a good definition of gamification

Gamification is the concept of applying game mechanics and game design techniques to engage and motivate people to achieve their goals.[1] Gamification taps into the basic desires and needs of the users impulses which revolve around the idea of Status and Achievement.

The main concept is making parts of process into a game and encourage competitive behaviour.

This sounds fun and funky but at it’s core you are measuring workers contributions with a score based system.  The purpose of the employer is to encourage the competitive instinct of your workers and encourage them to obtain more points.

Monitor

The monitoring and measuring (against co workers) seems a bit mean and possibly sinister but the reality is your bosses already compare your performance against your peers and this is traditional how pay rises are allocated, so it’s nothing new or something to fear.

I’m sure there are lots of bosses who would like to know what their employees are doing in more detail, with gamification they can can create a system to monitor and reward key tasks.

Teaching

The game elements interest me because when you play any computer games the points system teaches users how to become more effective at the game and how to get more points through action and the award of points.  It encourages innovation of processes and techniques to game (improve) the system and get more points.

Know who is effective rather than feel

One of the beautiful concepts of gamefiction is it can show you who are the most effective workers rather than using the often unscientific and potentially flawed method of opinion.  gamification makes companies assess the processes they go through and add value to those processes, it makes companies analyse what they do.

Changing Habits

People use habits to do common tasks without thinking too much, your brain goes on an auto pilot.  This is useful because it allows us to conserve some energy but the downsides are habits can be non thinking, doing tasks.  If you have a bad habit it means you instintively and repetitively doing something which isn’t particularly good for you e.g. eating too much, smoking, being messy, not sleeping enough.

At work people can get cultivatae average habits, which I would classify as habits which get your work done slowly.

Gamefication makes people analyse what they are doing and look to improve their working habits, swapping the ineffective habits with more effective habits.  The CRM users will get feedback from the points to help them find their average habits.

CRM gamified have a few articles on why gamefic

Fun

Would gamification make work more fun? hmmm I find this hard to believe but badges and points can motivate people in funny ways.

When the Microsoft Dynamics Community brought out new badges the gamer in me was urged to obtain them for seemingly little reward (does anyone care I have most of the badges is anyone impressed?)

Check out the Dynamics leaderboards here

Learn about Dynamics Community Badges here

I’m sure there are many people who have played a computer game on their computer/tablet/games system in order to get a power up, badge or level up, staying up late and depriving themselves of sleep to get it.

Incentives

Gamification tries to tackle the conceptive of incentivisation.  Are your workforce incentivised to work harder.  When I worked on a helpdesk in one of my first jobs, people were not incentivised to work harder and answer more helpdesk queries because

  • If you solved a query you were rewarded with more queries to solve
  • No one was measuring how many bugs/queries people solved
  • no one was rewarded for working harder.

Sales people are usually one of the few areas of the business who are incentivized to work harder due to commission based pay (e.g. you sell more you get more commission).

Games can be gamed

Games can be twisted by players to get more points.  If a company was using this system for dealing with incidents.  It could lead to players waiting for easy incidents to get more points rather than dealing with the incidents from the most important customers or priority cases.  I imagine there is a balance needed to reward the players but get the focus of the game aligned correctly.

Rules and configurations of games can be change, modified and adapted to ensure they are fairer.  This would be a vital part of the system because if the rules are not fair user adopted will drop.

Not all tasks are equal

The problem  with gamification is some tasks help everyone but the effect can be hard to calculate, not all tasks are created equal.

  • setting up shared information
  • automating processes
  • delivering letters

If sometimes necessary tasks are worth less points people will be less inclined to do them because of the opportunity cost (e.g. they could be doing a task which could get them more points).

Companies would need to think carefully about the rules of the game and possibly insist on a bit of turn taking.

Facts

Reading the interesting article mentioned at the start of this article

Microsoft Acquires FantasySalesTeam, an Innovative Sales Gamification Platform, to Help Organizations Increase Productivity

The facts quoted are impressive

  • Service Corporation International (NYSE: SCI) recently ran a pilot with 130 sales reps and compared their performance to almost 700 others. Those using FantasySalesTeam on average closed 88% more deals at 213% the average contract value.
  • Wireless Zone saw a 176% increase in total sales, 35% increase in specific product sales and a 9% increase in profit in the first month they ran FantasySalesTeam.

It would be fascinating to see the stats of the most successful sales people in terms of phone calls, emails, meetings in comparison to the least successful.  What are the more successful sales people doing, implementing gamefiction will not only highlight the most productive but give you a template as to what other workers need to do to emulate them.

Summary

Gamification is looking at the processes of a companies Microsoft Dynamics CRM system and trying to motivate people to use it more effectively.

I’m fairly certain it could make things more fun (who doesn’t like bettering their fellow workers) and reward people who are working effectively.

Interesting and I look forward to seeing how Microsoft will integrate the new company.

If anyone has any experience with Microsoft Dynamics and gamification please leave a comment I would interested to hear your experiences.

Testing CRM rollups and .NET versions

In this article I will talk about testing patches and how .NET versions can cause odd errors.

Rollups and CRM Version

I had a customer who was using CRM 2013 Service patch 1 and wanted to test their customizations still worked when CRM 2013 SP1 rollup 3 was applied.

Testing a new CRM service pack or rollup involves using a new server and CRM instance.

You can have many CRM organisations deployed on one CRM server but if you upgrade the CRM server it will effect all the CRM organisations and I don’t know any method to roll back rollups.

Why can’t you rollback CRM versions

To understand the question you need to think what happens (could happen) when you apply a rollup

  • Possible changes to the database tables
  • Update to CRM SDK
  • Depreciating certain functional in CRM SDK

Database changes

Microsoft might change the whole structure of the CRM database between service patches and rollups, which is one of the reasons Microsoft recommends you do not write any code/customizations/reports which run directly against the CRM database.  Microsoft provide filtered views and the CRM SDK for you to integrate the CRM database.

I think during the CRM 2013 update Microsoft used to have base and extension tables for each entity. e.g.

  • entitynameBase
  • entitynameExtensionBase

e.g.

  • accountBase
  • AccountExtensionBase

Here is some more information on the merging of tables, which explains how you can run the table merging as a separate job but you have to do it.

Run the base and extension table merge as a separate operation

I have written before about unsupported customizations before – Why you shouldn’t put unsupported customizations in Microsoft Dynamics CRM.  The primary reason you should avoid unsupported customizations is if you have to escalate an issue to Microsoft they offer limited support if you have unsupported customizations (because those customizations might be the cause of the behaviour/bug)

New functionality in CRM SDK and CRM

Usually (but not always)

  • Roll ups contains fixes
  • Service packs contain fixes and new functionality

New functionality doesn’t usually break anything but sometimes existing functionality might change.

The key point is the CRM SDK will have changed,

Old CRM SDK functionality depreciated

With one hand Microsoft giveth new functionality and the other hand they take functionality away (depreciate).

You should always read the What’s new for a new release of CRM – Why you should read the What’s new for developers because it lists not only the new functionality but includes what’s being depreciated in Javascript and CRM SDK.

Applied patches but stuff not working

I applied the rollup to CRM 2013 SP 1 rollup 3 but when I tried to test CRM, I noticed I was getting unusual errors.  The core functionality of CRM was working but I was getting errors when the plugins triggered calls to WCF web services.  Below is the error

The Web Service plug-in failed in OrganizationId: 3666c2e6-04f4-e411-80c9-000c292122be; SdkMessageProcessingStepId: 2ccabb1b-ea3e-db11-86a7-000a3a5473e8; EntityName: incident; Stage: 30; MessageName: Create; AssemblyName:
Inner Exception: System.TypeLoadException: Could not load type ‘System.Runtime.CompilerServices.ExtensionAttribute’ from assembly ‘mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)

To find this error I had to turn on tracing and look into the event logs because CRM was not giving much information.

I have highlighted the key part of the error.

This article was useful

Could not load type ‘System.Runtime.CompilerServices.ExtensionAttribute’ from assembly ‘mscorlib

This seemed a classic DLL type error, this usually occur when you there are differences between .NET versions or DLL’s deployed.

In this particular scenario I could compare the .NET version installed on the working CRM environment and the .NET version and other DLL’s in the new upgraded environment.

So I needed to check the .NET version, Microsoft has a great page on this

How to: Determine Which .NET Framework Versions Are Installed

Be careful because you have to read it carefully.  I was checking the .NET versions in regedit (full instructions in the link above) and the folder said v4.  I was expecting a 4.5 folder, so I assumed it was version 4.

Its a better to know facts rather than making assumptions particularly when trying to find a problem.  In the example above I assumed the .NET versions where the same, which meant I then wasted time investigating other parts of the server and DLL’s looking for potential problems.

If I had read the article more carefully  it more carefully I would have noticed this very important section

The value of the Release DWORD indicates which version of the .NET Framework is installed.

 

The folder will be v4 but if this has been updated it will have a new Release registry value and the number in this registry settings tells you what version of .NET is installed

.NET versions

 

I found there was a DWORD value in the working CRM Server which indicates I had 4.5.1 installed

378675 .NET Framework 4.5.1 installed with Windows 8.1 or Windows Server 2012 R2

I checked on the server I was updating CRM 2013 SP 1 to rollup 3 and it only had .NET framework 4

What was happening was the web services were compiled with .NET 4.5 but when they tried to run on the new server it couldn’t find the correct dll versions, this caused the odd errors.

What I learnt

Don’t make assumptions – Know don’t assume.

If web services are not working check the .NET versions and look for the secret DWORD registry setting Release.

 

Hosk’s Top CRM Articles of the week – 24th July

Article of the Week

Asynchronous Batch Process Solution Revisited – part 1

Asynchronous Batch Process Pattern: Part 3

I enjoyed reading these two articles

Best of the Rest

CRM 2015 – Understanding impersonation in plugins and knowing when to use it

A look at plugins and understanding impersonation, when, why and how to use impersonation

Updating and Publishing webresources directly from Visual Studio

A tool to update web resources from Visual studio

MICROSOFT ANNOUNCED ITS CERTIFICATION FOR DYNAMICS CRM ON-PREM RUNNING AZURE IAAS

It’s finally certified

CRM 2013 – Workflow error AccessCheckEx

The Hosk got an error, find out how I worked out the cause and my solution

Querying More than 5000 records in Dynamics CRM

Interesting article talking about paging when selecting lots of records

CRM 2015 – What is the CRM Outlook reading Pane?

The CRM outlook reading pane caused me problems this week

Visual Studio 2015 Shared Projects and CRM Plugins Development

Excellent new functionality in Visual Studio 2015, help you get round the dll/ilmerge problems

CRM 2015 – Understanding CRM Metadata

What is Metadata in CRM 2015

Tracking the Movements of a Case

Leon Tribes shows how a no code solution to tracking the history of a case.

Microsoft Dynamics CRM Mobile SDK Update and Azure Mobile Connector SDK

CRM SDK for Mobile and Azure

CRM 2013 – Understanding SystemJobs and Async Plugins

Understanding System jobs and async plugins

Using Windows Resource Monitor to Find Unusual Performance Bottleneck

Great use of windows resource monitor to diagnose a problem

How to cascade activate / deactivate (SetState) in CRM

Do you know your cascading

Getting the CRM Developer toolkit working with Visual Studio 2013

Tutorial to get CRM Developer toolkit working with visual studio

programming

Announcing the latest improvements for the F12 developer tools in Windows 10

Group Flow in Software Development

7 Tools to help you gather better software requirements

Building your mental toolbox for solving coding problems

Other articles interesting the Hosk

free minding hacking book

awesome mind maps/sketches of books

Why Exercise Won’t Make You Thin

Billy Beane on Making Better Decisions and Avoiding Biases

Mental Model: Regression to the Mean

BBC iPlayer ‘watched by more than 60 million people outside the UK for free’

“How To Pick The Perfect Book Title”

short master course on Thinking about thinking

Previous top picks

Hosk’s Top CRM Articles of the week – 17th July

Useful Hosk Links

Hosk list Of CRM 2013 Tools

A list and review of CRM 2013 tools, this will probably work in CRM 2015 as well

Hosk’s CRM Developer Articles

A collection of my favourite CRM Developer articles I have written

MB2-703 – CRM 2013 Customization and Configuration Certification Information

All the CRM 2013 content to help you pass the exam

HoskWisdom – Hosk Developer Quotes

 Words of Wisdom from the Hosk.  I have written over 900 articles, surely I should have said a few memorable things

CRM 2015 – What is the CRM Outlook reading Pane?

I have started using CRM 2015 SP1 and the navigation tweaks are awesome.  So I will congratulate Microsoft on the navigation tweaks and wonder how they got it so wrong in CRM 2013!

The Outlook reading pane is a pain, that’s not entirely true but for an hour today it caused rampant confusing and gnashing of teeth.
I will explain the problem I had first.
CRM Developer Joe was perplexed because the CRM form being shown in Outlook wasn’t the same as the CRM form he was customizing.  He asked me why, why, why, why was this happening.
The contact form looked different than the information in outlook, except if you clicked on the contact it opened a CRM form which looked the same?!?!?!
Contact form in CRM Web
contact form

Outlook contact form but it still has fields which were removed from the contact form.
contact form outlook

So what’s the problem?

I haven’t used the CRM outlook add-in for ages, so I had to do a bit of clicking and looking around.

Searching the internet didn’t bring up anything useful, which was odd because if this was a problem then lots of people would have mentioned it.

Think, Think, Think, Think

I wondered if Outlook wasn’t refreshing properly but after un-installing and installing it still didn’t fix it.

I ended up clicking around and looking for settings, I then clicked on view.  Hmmmm Customize Reading Pane, what does that do?

custom reading pane

So I clicked it

custom reading pane 1

 AHA

The data which was being shown was the Reading Pane and the data it shows are not customizable (except you can remove some sections if you want).

What is the CRM Outlook reading pane?

The reading pane is a quick way to view contact information in a read only view.  It’s useful Microsoft have provided some quick view functionality, frustrating you can’t edit it and puzzling I couldn’t figure out where this information was coming from.

If you think of the CRM reading pane working like the normal Outlook reading pane, which shows you some details about an email without you having to open/read the email.

The CRM reading pane works in a similar way, showing you some details about the contain without having to open the contact record.  This works OK except when you have customized the contact record significantly because the new fields won’t be shown in the reading pane and fields you have removed from the form will be displayed

More information

Customize the Reading Pane in CRM for Outlook

Navigating the CRM Outlook Client

How to Hide Tabs in Reading Pane for Dynamics CRM Outlook Client

CRM 2013 – Workflow error AccessCheckEx

I was investigating a bug on CRM 2013 , I got the exception below

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: SecLib::AccessCheckEx failed. Returned hr = -2147187962, ObjectID: f115e97d-8e19-e511-80ca-000c292122be, OwnerId: 89ed0bdd-7ecd-e411-80c7-000c292122be,  OwnerIdType: 9 and CallingUser: 2ed69167-0bcf-e411-80c7-000c292122be. ObjectTypeCode: 4200, objectBusinessUnitId: 5f964320-05f4-e411-80c9-000c292122be, AccessRights: WriteAccess Detail:
<OrganizationServiceFault xmlns:i=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns=”http://schemas.microsoft.com/xrm/2011/Contracts”&gt;
  <ErrorCode>-2147220891</ErrorCode>
  <ErrorDetails xmlns:d2p1=”http://schemas.datacontract.org/2004/07/System.Collections.Generic”&gt;
    <KeyValuePairOfstringanyType>
      <d2p1:key>OperationStatus</d2p1:key>
      <d2p1:value xmlns:d4p1=”http://www.w3.org/2001/XMLSchema&#8221; i:type=”d4p1:string”>0</d2p1:value>
    </KeyValuePairOfstringanyType>
    <KeyValuePairOfstringanyType>
      <d2p1:key>SubErrorCode</d2p1:key>
      <d2p1:value xmlns:d4p1=”http://www.w3.org/2001/XMLSchema&#8221; i:type=”d4p1:string”>-2146233088</d2p1:value>
    </KeyValuePairOfstringanyType>
  </ErrorDetails>
  <Message>SecLib::AccessCheckEx failed. Returned hr = -2147187962, ObjectID: f115e97d-8e19-e511-80ca-000c292122be, OwnerId: 89ed0bdd-7ecd-e411-80c7-000c292122be,  OwnerIdType: 9 and CallingUser: 2ed69167-0bcf-e411-80c7-000c292122be. ObjectTypeCode: 4200, objectBusinessUnitId: 5f964320-05f4-e411-80c9-000c292122be, AccessRights: WriteAccess </Message>
  <Timestamp>2015-06-23T10:02:24.458209Z</Timestamp>
  <InnerFault i:nil=”true” />
  <TraceText>

[Microsoft.Crm.ObjectModel: Microsoft.Crm.ObjectModel.SyncWorkflowExecutionPlugin]
[0dac4467-fb18-e511-80ca-000c292122be: ]
Starting sync workflow ‘Task-Workflow’, Id: 04ac4467-fb18-e511-80ca-000c292122be
Entering ConditionStep1_step: If  Process contains data and is active
Entering SetStateStep4_step: Change record status to completed
Sync workflow ‘Task-Complete’ terminated with error ‘SecLib::AccessCheckEx failed. Returned hr = -2147187962, ObjectID: f115e97d-8e19-e511-80ca-000c292122be, OwnerId: 89ed0bdd-7ecd-e411-80c7-000c292122be,  OwnerIdType: 9 and CallingUser: 2ed69167-0bcf-e411-80c7-000c292122be. ObjectTypeCode: 4200, objectBusinessUnitId: 5f964320-05f4-e411-80c9-000c292122be, AccessRights: WriteAccess ‘
</TraceText>
</OrganizationServiceFault>

Initial thoughts on the Error

I got this error and there were a few things I found interesting

This error was surprisingly informative

The error was thrown by a non code workflow but the cause of the error was thrown by a GUI workflow which was being triggered when a workflow tried to assign an activity.

I was impressed by the level of logging which was generated by a GUI/non code workflow.

I had never thought about it but this line

Microsoft.Crm.ObjectModel: Microsoft.Crm.ObjectModel.SyncWorkflowExecutionPlugin

indicates CRM runs the GUI workflows using code, which must translate the actions into code. This is obvious but I hadn’t thought about it, until seeing the error.

You can use the callerid to find what user is doing the update and check what security roles the user has.

EntityTypeCode

In the error message you can see it mentions ObjectTypeCode

CRM 2011/2013 – Javascript to get the object type code of an entity

Each entity has an individual typecode, this CRM SDK page shows you the values of the default entities

Entity Type Code 4200 is ActivityPointer, which is interesting because the problem was being caused by an update to a task record.

Clues

AccessCheckEx failed – AccessCheckEx is something to do with security and access

In the error message you can see

AccessRights: WriteAccess

This is clearly telling us the user doesn’t have Write access, e.g. the user isn’t allow to update a certain

What was the cause

This bug was partly caused by the complexity of the CRM solution and the different customizations.

Solution complexity refer to not only the customizations which exist in the solution but the number of different customizations.  When a CRM solution has lots of different customizations e.g. workflows, plugins, business rules being triggered at the same time it makes it difficult to understand what is changing a value.

Below is what was happening

  1. A task was updated then saved
  2. This triggered a pre plugin on the task entity
  3. The plugin assigns the case record
  4. A plugin was triggered on assign of the case, which assigned all the open tasks to the new case owner
  5. The plugin(s) finished
  6. A workflow was triggered, which tried set the task to complete.

The error was thrown because the workflow was trying to update the task but the user only had privileges to update tasks they owned.

The reason this bug suddenly appeared was because the assign plugin was added and it wasn’t picked up in DEV testing because developers tested the code using users with System Admin privileges, which I have talked about before

The System Administrator role is a benefit and a curse to CRM developers

It’s tricky to test the effect of adding plugins

Having lots of different types of customizations adds to the complexity of your CRM solution, complex solutions are difficult to debug, understand and extend.

The Solution

Usually with bugs where the user doesn’t have the right security privilege the easy answer is to give the user role those security privileges.

For this bug it wasn’t the correct solution because the users only had access to tasks they owned and we didn’t want to suddenly give them permissions to update tasks they didn’t own.

The plugin code was running in a PRE plugin, so I couldn’t move the task completing code into this plugin.

The bug was becoming more tricky because I did want to keep the case assigning code in their but I didn’t want the assigning case plugin to run and assign the task to the new case owner because the task was about to completed.

My solution was to stop the assign plugin being triggered if was called by another plugin

Read how to do that in the blog below

CRM Plugins – Stopping infinite loops and understanding PluginExecutionContext.Depth

I then created a post task plugin to complete the task.  I didn’t need to do this but it seemed it would be easy to understand if all the changes were made by plugins.

There was an unsuccessful fix when I used impersonation to close the task as System Admin but the users didn’t like the tasks being closed by System Admin, they wanted the user who updated the task to complete the task.

You can read about Impersonation in plugins in the blog post below

CRM 2015 – Understanding impersonation in plugins and knowing when to use it

CRM 2015 – Understanding impersonation in plugins and knowing when to use it

Plugins are usually set to run as the calling user but sometimes you need to run a plugin with System User privileges.

Before I explain how, we should first look at the why and how you impersonate users inside a plugin

I have been writing a bit about plugins recently

For some step by step guides to creating plugins check out the CRM Code examples section on the page Hosk’s CRM Developer Articles, I created some Youtube videos CRM 2013 Plugins

What is impersonation

When you create a plugin in CRM (step by step blog post here) you write an execute method which gets passed in

IServiceProvider serviceProvider

This has lots of variables and objects such as

  • IPluginExecutionContext
  • ITracingService
  • IOrganizationServiceFactory

You use the IOrganisationServiceFactory to create a IOrganizationService.  The IOrganizationService is the CRM SDK, it provides you access to CRM programmatically .  CRM developers use the IOrganizationService (which I will often call CRMService) to

  • CRUD operation – Create, Retrieve, Update, Delete records in CRM
  • Assign records
  • Change status
  • pretty much everything you can do in CRM

Here is the code to create the IOrganizationService, taken from the Plugin class of the CRM Dev toolkit

// Obtain the Organization Service factory service from the service provider
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

// Use the factory to generate the Organization Service.
this.OrganizationService = factory.CreateOrganizationService(this.PluginExecutionContext.UserId);

When creating your plugin you will notice there is a Run in Context setting, most of the time you will choose to Run In Context of Calling User.

Create Account Plugin 1

99 percent of the time Calling User is the right choice

It’s usually the right choice to use the Calling User because any updates, retrieves or any interaction with CRM data will be done using the calling users identity and privileges.

If you visualize a plugin as an automated extension of the CRM form, it’s likely you want the the code in the plugin to run with security privileges as the calling user.  It allows you not to abdicate the need to apply security to the plugin code and pass this off the users security profile and CRM.

The PluginExecutionContext (which I explain in this blog post) has the field called UserId.  We pass this to the IOrganizationFactory to create an IOrganizationService with the user who initiated the plugin.  The good news is the CRM Dev toolkit does all this for us, so we can just chill out and get the IOrganizationService and work on the business logic.

// Use the factory to generate the Organization Service.
this.OrganizationService = factory.CreateOrganizationService(this.PluginExecutionContext.UserId);

Running the CrmService (IOrganizationService) as the calling user means you are interacting with the data in CRM as the calling user, which means

  • The IOrganizationService can only retrieve data the user can retrieve
  • When IOrganizationService updates, creates records they are stamped with the calling user
  • The plugin cannot do anything the calling user cannot do

The calling user setting adheres to the security role assigned to the calling user, integrity of your precious CRM data is kept intact.

Why impersonate System User

If running plugins as the calling user is so good, why impersonate other users or system admins.

  • What if you need to retrieve records the user doesn’t have access to?
  • What if you need to update records the user doesn’t have access to?

You might be thinking, “if the user doesn’t have access to those records, maybe the plugin shouldn’t be updating them”.

It’s a point to consider point but sometimes you want to create records or update records based on the action/status of an entity to move the code to the next stage/state.

Sometimes you want to assign a record to another user when a record goes to a certain state but you wouldn’t want users to be able to assign records.

How is running in context different from impersonation

The running in context setting on a plugin mentioned early runs the whole plugin in that context.

Impersonation allows you to run a small section of code in another context.

Impersonation gives the CRM developer more flexibility to target a particular action in a plugin they would like to run with elevation permissions.  The rest of the plugin actions can be run as

Dangers of impersonation

The downsides of impersonation is it potentially gives users running the plugin\custom workflow enhanced security privileges which could lead who we don’t want updating\deleting records doing exactly that.

When using impersonation in plugins consider accountability and audit trails.  When a plugin impersonates a system user or a different user, the impersonated user will update those records.  It can be confusing/worrying for users when looking at audit records to see System Admin updating records.

I’m sure there have been thousands of support calls querying why System Admin has been updating records.

Impersonation Code

Easy way to impersonate System User is to pass null to the CreateOrganizationService and it will run as System user, find out more in this CRM SDK article

// Use the factory to generate the Organization Service.
OrganizationServiceImpersonated = factory.CreateOrganizationService(null);

 

You can pass in a different user Id to the CreateOrganizationService to create an IOrganizationService

IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.InitiatingUserId);

The sample code in the CRM SDK article impersonates using OrganizationServiceContext.  I personally have used this

Sample: Impersonate using the ActOnBehalfOf privilege

// Retrieve the system user ID of the user to impersonate.
OrganizationServiceContext orgContext = new OrganizationServiceContext(_serviceProxy);
_userId = (from user in orgContext.CreateQuery<SystemUser>()
where user.FullName == "Kevin Cook"
select user.SystemUserId.Value).FirstOrDefault();

// To impersonate another user, set the OrganizationServiceProxy.CallerId
// property to the ID of the other user.
_serviceProxy.CallerId = _userId;

Impersonating during plugin-in registration

You can impersonate a user during plugin-registration but I’m not entirely sure why you would do this, so I’m not going to talk about.  Most CRM developer will impersonate someone inside a plugin.

If you want to learn more read

Impersonate another user

and the articles in the futher reading section

Why, What, Where, When

What is Impersonation

Impersonation in plugins/custom workflows is creating an IOrganisationService as a different user

Why use Impersonation

Use impersonation when you need to update/retrieve/delete/Create records users security roles doesn’t let them.

Where

If you don’t want to increase users security roles but still want the plugin to do a particularly action.  e.g. delete a record

When

You use impersonation in plugins/customer workflows

 

Further reading

Scott Durow has an excellent article on Impersonation

User Impersonation in Plugins, Workflow and Dialogs

CRM SDK 2015 impersonating User in plugins

Dave Berry does a good job explaining Impersonation – CRM Impersonation Explained

Awesome Pixar impersonation picture from here

Hosk’s Top CRM Articles of the week – 17th July

Article of the Week

The article of the week is my trilogy of articles on plugin code

  1. Are your CRM plugins creating technical debt?

  2. Are CRM Developers are afraid of creating classes?

  3. How to find classes

The articles look at the effect of creating plugins and putting all the code inside the plugin class, the benefits of creating classes and how to find classes when creating code.

Non Hosk article of the week

Dynamics CRM and ILMerge: The Easy Way to Merge DLLs for Plugins

It’s an old article but a good step by step guide to using ILMerge

Best of the Rest

check out the plugin tracing in CRM 2015 sp1

The ability to see the trace file in plugins will dramatically help investigating live issues.

CRM 2013 – Understanding Auditing, Tips, Tricks and Gotchas

A good long look at auditing by the Hosk.

How to handle Nulls in Dynamics CRM Calculated Fields

Interesting article on handling nulls in calculated fields

CRM 2013 – Javascript null setting oddity

A Hosk article investigating why a field wasn’t being set but delves into requirement levels and debugging

Microsoft acquires FieldOne, global provider of field service management solutions for the enterprise
video

Another new business purchased by Microsoft

Dynamics CRM: Extensions to Improve IOrganizationService

Good use of extensions to ease CRM Development

What are Preview features and how do I enable them?

New preview functionality has been added to CRM 2015, check it out

Accessing related entities fields in Calculated Fields formulas in Microsoft Dynamics CRM 2015 Online Update 1

Debugging Plug-in Made Easy for Dynamics CRM Online

A step by step guide to debugging plugins using the plugin registration tool

Microsoft Dynamics CRM not working? check these common causes

What to check if CRM stops working

Restrict customer lookup to select a specific entity records in CRM 2013/2015

Adding filters to lookups in Javascript

What’s new in CRM 2015 SP1 for developers, customizers and admins

A run down of the new features in CRM 2015 SP1

programming

Get off Your Horse and Stop Coding like a Cowboy

Second System Syndrome

interesting discussion – Over 40 years, has Software Gotten Better or Worse?

Other articles interesting the Hosk

How Bold Entrepreneurs Are Breaking $1 Million In One-Person Businesses

Microsoft ruined Nokia – WHY. Microsoft and Nokia – a marriage made in hell?

How Changing Our Product Team Structure Doubled Productivity

Annoying practices of bad recruitment consultants

Microsoft marketing manager plays the blues

Elon Musk’s high-speed Hyperloop train makes more sense for Mars than California

Here’s what happens to your brain when you give up sugar for Lent

The Stoic: 9 Principles to Help You Keep Calm in Chaos

teaching maths Asian style

What I learned from a McDonald’s Manager

Previous top picks

Hosk’s Top CRM Articles of the week – 10th July

Useful Hosk Links

Hosk list Of CRM 2013 Tools

A list and review of CRM 2013 tools, this will probably work in CRM 2015 as well

Hosk’s CRM Developer Articles

A collection of my favourite CRM Developer articles I have written

MB2-703 – CRM 2013 Customization and Configuration Certification Information

All the CRM 2013 content to help you pass the exam

HoskWisdom – Hosk Developer Quotes

 Words of Wisdom from the Hosk.  I have written over 900 articles, surely I should have said a few memorable things