What’s new in CRM 2016 and why you should read the preview guide

We keep moving forward, opening new doors, and doing new things, because we’re curious and curiosity keeps leading us down new paths.

Walt Disney

 

I go on holiday to Butlins for a week and Microsoft release a new version of CRM, well not actually release but an outline of what’s coming in CRM 2016 and the CRM community is vibrating with blogs, articles and general excitement of a new release.

There is a difference between theoretical knowledge and practical knowledge (a concept I talked about in this blog Why CRM Developers should always start with the CRM SDK), in a similar way there is a difference between functionality in the CRM 2016 preview guide and the functionality included in CRM 2016.

Working with Microsoft Dynamics CRM we must keep our eyes on the horizon scanning for new versions of CRM getting read to land

What is CRM 2016 preview

The preview document gives you a guide to the new features likely to be included in CRM 2016 but the features and functionality described in the preview document can be

  • Amended
  • Removed
  • New features added
  • Deprioritized

At this late stage it’s unlikely the functionality will change much but be aware functionality can change

New releases of Microsoft Dynamics CRM are exciting

  • There is always a new look and feel to CRM
  • Great new functionality for Sales men (like dashboards etc)
  • Useful new functionality for Developers
  • A bunch of Gotcha’s and limitations

The preview guide gives us a glimpse of the future, a road sign to help us anticipate the impact CRM 2016 will make.

The features might change but at least we have an idea of the new functionality and importantly what technologies or products are going to be used to deliver the new functionality.

Why you should read the CRM 2016 preview guide

The Scouts motto is be prepared, the handbook describes this in more detail

  • Be Prepared in Mind by having disciplined yourself to be obedient to every order, and also by having thought out beforehand any accident or situation that might occur, so that you know the right thing to do at the right moment, and are willing to do it.

The Scout’s had some good values because it’s not the first time I have used their advice.

Why you should write code and customizations like a boy scout

Being prepared allows you to survive but knowing the future functionality in CRM 2016 allows you to use this as an opportunity to take advantage by aligning your technical skills to the technology used to deliver the new functionality.

If you know what’s coming, you can position yourself to take advantage of it

Reading the preview guide you can see what functionality is coming, allowing you to prepare your skills and knowledge, enabling you to position yourself to start utilizing the new functionality.

Sometimes CRM developers can feel like Microsoft are constantly adding new features and not giving developers/consultants/solution architects time to get used to new functionality.

The reasons for reading the CRM preview guide are the same reasons CRM developers should read the What’s new for developers in the CRM SDK.

  • Knowledge
  • Start to prepare
  • Analyse the suitability of customizations for existing CRM projects
  • be prepared (Scouts motto)

There are some additional reasons you should  the CRM 2016 release notes

  • It’s not very long
  • you get an idea of what’s coming
  • a chance to see if anything exciting is coming
  • You can start to prepare
  • it’s decent CRM network conversation
  • Adjust your learning to focus on technology used in CRM 2016 (mobile, Azure Machine Learning, etc)

CRM Online customers

One aspect of CRM Online I found concerning from a CRM developers perspective is the process of updating the CRM version.  When ever a patch, service update or new CRM version is released the CRM customizations could stop working and you need to test ALL the customizations.

Testing all the customizations for complex projects can be take a lot of resources (people) and organising, so it’s important you are in control of this process.

Microsoft addressed this by allowing users to turn off the automatic updates but I’m not sure what happens for a new release or if you can turn off the updates indefinitely?

This technet article discussing managing CRM online updates (you have to approve the update)

Manage Microsoft Dynamics CRM Online updates

The document states updates are mandatory but you can have only one update per year

this update becomes mandatory and the customer will be required to take the update during the available dates for that particular release.

 

The thought of a CRM instance having to update to a new version causes my CRM developer heart beat to start racing.  Imagine if this happened to all the Microsoft Dynamic CRM projects I have worked on, this is another great reason for CRM developers not to write unsupported code

On the positive side this should make plenty of work for CRM developers, whilst they check their customizations work in the new release of CRM 2016.

CRM is constantly evolving

I view new release of Microsoft Dynamics CRM with excitement and In trepidation

It’s a wonderful world. You can’t go backwards. You’re always moving forward. It’s the wonderful part about life. And that’s terrific.

Harvey Fierstein

 

 

A CRM Developers life and CRM surroundings are constantly changing with major new releases coming once a year (new release or service pack update I classify as major release)

It’s exciting and sometimes tiring trying to keep up with change inside Microsoft Dynamics CRM.

CRM developers have new functionality to learn and master, CRM developers are constantly challenged.

CRM developers/CRM professionals need to work hard to keep up with the latest releases and functionality but with this difficultly comes opportunity.

With every new release of Microsoft Dynamics CRM you have the opportunity to become an expert in the new functionality, the go to person.

A key skill of the CRM developer is knowing what customization to use for a particularly customer requirement.  Microsoft Dynamics CRM is extremely versatile and required functionality can be achieved using different customizations but there is usually one type of customization which is ideally suited.

CRM developers know the different  versions of the CRM SDK and always start by referring to it

Key Information for the CRM 2016 Preview

The key information about the CRM 2016 preview can be found below

Release Guide link

Microsoft Dynamics CRM 2016 release guide

Microsoft Blog links

Microsoft reinvents productivity with upcoming release of customer engagement solution

Bob Stutz blog post

Microsoft Dynamics CRM 2016 – Delivering the Next Generation of Intelligent Customer Engagement

Release Date

Microsoft Dynamics CRM 2016 — in Q4 of this calendar year.  I find it amusing Microsoft can release CRM 2016 in the year 2015!

Microsoft Video Link

Microsoft Dynamics CRM 2016 Release Overview

Grand Quotes

I thought I would put some of the quotes, I love the idea of releasing quotes like this when I have created some code for a bugfix, maybe something like

“With this bug fix I have designed the code from the ground up to deliver the core functionality in one bug fix, which eliminates distractions and should dramatically increase customer productivity.  I have made field read only.”

Over exciting quotes from Bob Stutz and Microsoft

“We are eliminating the distractions people inevitably encounter when they bounce from application to application in the course of doing their job by taking away the need to export or switch applications, and by automating fundamental tasks.”

 

“Dynamics CRM 2016 is designed from the ground up to deliver core capabilities all in a single system to eliminate distractions, to make it easier to get things done, and to dramatically increase productivity so our customers can spend more time serving their customers.”

 

One quote from Microsoft press release

“The most comprehensive upgrade ever for Dynamics CRM includes advancements in intelligence, mobility and service, with significant productivity enhancements to help businesses and workers achieve more”

 

The direction of CRM 2016

Before looking at the functionality I want to highlight the broad direction of Microsoft Dynamics.

Microsoft have a clear hierarchy in platforms 

Cloud first, mobile second, on premise last

Microsoft’s policy of updating CRM on premise versions 6 months later definitely seems Microsoft’s way of gently persuading everyone to use the CRM online version.  I have talked about this before

What are the limitations of Microsoft Dynamics CRM Online and how do you work with them?

This seems a strange tactic because there are lots of reasons (data, complexity) why some CRM solutions are better suited to CRM On Premise.  Microsoft recently announced their Cloud certification to allow CRM on premise solutions to move to private cloud/Azure platform, which I blogged about here.

I’m don’t understand why Microsoft are making their current CRM on premise customer wait six months when you consider these are likely to be larger deployments.  I don’t understand the 6 month delay at all, it’s confusing to customer, developers, everyone and isn’t going to persuade anyone to move from On Premise to CRM online????

Machine Learning

Machine learning sounds really interesting and using customers data to make recommendations and suggestions would be awesome.

Social CRM

Social CRM is moving from listening to interacting and integrating with the customers CRM data.

Integration

Microsoft are continuing to slowly to properly integrate their companies and products they purchased.  Parature integration is looking to bring in the powerful knowledge base functionality into CRM (whilst also Microsoft are creating their own knowledge base functionality!!!).

I find the slow rate of integration a bit puzzling, Microsoft purchased Parature ages ago.

CRM 2016 Hosk Notes

Here are my thoughts on the CRM 2016 preview guide, this is a developers eye view.

Below are my brief notes on the CRM 2016 preview guide

Productivity

  • CRM App for Outlook
  • Excel templates
  • Delve

Microsoft as a company seem to be focusing on improving productivity of office workers.  This involves integrating Microsoft’s differences products\services and the increased use of machine intelligence.

Intelligence

  • Cortana Analytics suite and machine learning
  • Intelligence product suggestions
  • recommend cases
  • Machine Learning

Personally I’m not interested in Cortana, I don’t want to talk to my computer or CRM but Microsoft keeps working at it, integrating into more applications so I am probably going to need to get used to it.

The machine intelligence is one area I find really interesting.  I view it as CRM using the customers data to help, recommend similar cases or knowledge articles for the case your are working on.  Intelligent product suggestion based on your selected choices.

I imagine it working in a similar way to Amazon using your viewing history and purchasing history to recommend other products.  If Microsoft can add this type of functionality into CRM then it would be fantastic.

I currently have no idea how Azure Machine learning works and my mind boggles at how you would set it up??

Mobility

  • Offline capabilities
  • Task based mobile apps
  • Cortana

The mobile app is slowly getting better but my question to Microsoft is why is it taking so long?  This is almost 3 years of development on the mobile app now.  Progress is being made, offline capabilities for mobile apps are always good and Task based might make it more useful in some circumstances.

Unified Service

  • Field Service (a company/product Microsoft purchased last year)
  • Parature knowledge management (meant to be very good)
  • Native Knowledge management

Integration between the purchased products continues slowly

Marketing

  • SMS Marketing – {shudder}, I don’t think I have ever received a welcome SMS message.
  • Email – view Generated HTML

HTML emails are great, SMS marketing is a bad concept (no one likes receiving text messages, its like a pop up for phones)

Interesting stuff from a CRM developers perspective

  • Bulk Data Loader for CRM online
  • a new cloud service to bulk import/export data in Dynamics CRM online.
  • support for reoccuring data import/export
  • Modern Web API – OData v4

There isn’t a great deal for developers to get excited about but the developer tweaks are not usually mentioned in the preview guide (they look at high level functionality and new features).

The new OData v4 will be awesome

The bulk loader sounds interesting because a lot of projects use Scribe to insert data and this could potentially avoid that cost.  The bulk loader can also doing regularly/reoccurring imports and exports

Excel

  • Excel templates
  • Excel What if analysis

Excel is good because most people are comfortable with it, it’s easy to use and people can open it up and try it.  Most companies have an excel license so it doesn’t cost.

The new templates will work by opening an excel document and merging it with a template, which means it should be quick

Document generation – pre defined templates

  • A merge between an instant document and templates.
  • Document templates are role based
  • Work for Word and Excel.

This sound like a great idea.

External Party Access

An API to allow third parties (customers, partners) to access CRM data.  You model the access inside CRM.

Wow, sharing CRM data for third parties.  The question I have is how would the licensing work for this?  How will this fit in the current 2000 different licences you can currently use.

Mobile

  • Can view IFrames!
  • Disable copy and paste to stop data leakage
  • Enforce Encrpytion
  • offline

Some good features added here

Social CRM

  • Interact with customers
  • Publish tweets and facebook posts

The move from Social listening to social interaction makes the social CRM functionality really start to work.

Social  CRM is or will be a key area in customer support and the ability to respond to social media events in cases will become increasingly important.

I will be interested to see how the preview differs from what is actually implemented.

Quote from the preview guide

In addition to Twitter, Facebook, Blogs (WordPress/Tumblr), Videos (YouTube) and News, you will now be able to search boards/forums and custom sources via RSS. This includes internal non-public sources, like Yammer

Guided User Experience

This will probably be very useful to new users but I can already imagine it’s going to be really annoying to experienced users as CRM keeps popping up with advice and guidance (go away you damn paperclip)

Azure Machine Learning

  • Product Cross Sell recommendations
  • Suggested Knowledge based articles

Further reading

don’t forget CRM 2015 rollup

Just because everyone is talking about CRM 2016, don’t forget there has been a patch for CRM 2015

Get Ready for update CRM 2015 1.1

 

What are the limitations of Microsoft Dynamics CRM Online and how do you work with them?

will all CRM instances be online is the future?

Why haven’t I worked on more CRM online projects?

I was contemplating the questions above reading the white paper about creating solutions for CRM online

Microsoft Dynamics CRM Online patterns & principles for solution builders

It’s a white paper highlighting the limitations of CRM online and how Solutions architects will need create solutions to work with the strengths of CRM online and work around the weaknesses.

Is CRM Online the future of Microsoft Dynamics CRM?

Microsoft would like to think CRM projects are all heading online, Microsoft is spending lots of money creating data centres , bringing their top software offerings to the cloud(Exchange, Sharepoint, Dynamics CRM, Azure, Office, etc etc etc).  Making it easy for all the software to work together on-line (e.g. removing barriers)

Microsoft acquired online products to extend Microsoft Dynamics CRM

  • Parature
  • Social Engagement
  • MDM – Marketing

From a cost point of view (looking at it holistically), it seems sensible use massive data centres which are maintained and look after, rather than individual companies having to host servers, hire skilled people to maintain them.

Hosk experience of CRM online

So far I have only been involved in small/simple projects successfully working with CRM online.

The majority of projects I have worked on and have known about have been with CRM On premise.  I wonder if I have worked on complex CRM projects because I am a CRM developer, it’s perhaps more likely the projects I work on will involve complex customizations and with the previous versions of Microsoft Dynamics were better suited to CRM on premise.

I have heard of projects moving from CRM online back to CRM on Premise but no projects moving from CRM On premise to CRM online.

CRM online is growing?

Microsoft Dynamics CRM online is growing in popularity.  I say it but I couldn’t find much information to back that up

Good Momentum For Microsoft Dynamics CRM Reported At Their Fall Analyst Event

The Dynamics product is doing well. The numbers speak for themselves: 12% revenue growth in FY13; Dynamics AX and CRM growing by double digits worldwide and 30% in the Americas and Asia; and CRM Online growing by 80% in FY13, with two out of every three new customers opting for cloud. Microsoft Dynamics has 359,000 customers and 5 million users, while Microsoft Dynamics CRM has 40,000 customers and 3.5 million users.

The post is a few years old but I’m going to going to assume Microsoft Dynamics CRM online is growing.  I will assume Microsoft will actively continue to grow the Microsoft CRM online offering, which will result in more CRM online projects for CRM Developers to work on.

It’s easy to envisage a future where companies pay for virtual cloud servers and services instead of paying for skilled IT guys to look after their own servers.

At the moment my personal view is big CRM projects and complex CRM projects are not a good fit for CRM online.

Limitations of CRM online

Below are some of the limitation of CRM online

Indexing

A lot of CRM projects I have worked on have involved SQL indexing.  I understand indexes are not automatically added because when indexes need to be added it has to be in a specific area which needs a performance improvement.

How does indexing work with CRM online?  how do you find out where the SQL server is running slowly?

The white paper says you can get Microsoft engineers to look at indexes through a support request but I wonder how this works and how effective it is?

Increasing performance – How?

CRM on premise infrastructure is designed to allow more resources to be added in a modular way.  e.g. if you need more performance in the SQL server, you can add more SQL servers.  If you need better performance on the CRM front end, you add more CRM front end servers.

How does this get managed on line?

Data privacy

Some companies don’t want to their data in the cloud no matter how secure Microsoft says it’s is.

Sandboxed plugins

Sandboxed plugins can’t access any 3rd party dll’s, which can be quite limiting

Custom ASP.NET pages

Custom ASP.NET pages can’t be done in CRM online, so no iFrames showing custom pages.

Reports are FetchXML

CRM online reports can only be written in FetchXML because CRM developers have no direct access to the CRM database.

Size of database

Online database charge by the gigabyte.  CRM databases can grow pretty quickly but how do you shrink POA table if gets to big.

The emphasis will be on CRM support engineers to reduce the POA table size but the Microsoft as a company do not benefit from this (because they charge by the GB), so there is conflicting goals.

Reading the document has made me aware of techniques to move data out of the CRM database into services like SharePoint (or similar) but database management could be a full time job.  The alternative of course is there will be so much space available in the future where database size is not an issue.

The current relationship between megabytes and gigabytes could be the same relationship between gigabytes and terabytes in the future and the talk about database size seem silly.

Hosk Thoughts

if Microsoft keep investing in the Online infrastructure and products and more companies use CRM online then I will inevitably get increased exposure to CRM online.

I view CRM Online similar to CRM mobile in the fact it’s the direction the industry is moving but currently this seems to be a slow process and I expect the majority of CRM project to be CRM on premise.

I’m not sure why Microsoft are delaying service updates to CRM on premise?  It’s going to make CRM developers and resellers life increasingly complex and frustrating, delayed enhancements don’t seem appearing enough to change peoples suitability or desire for CRM version.

In my experience big or complex CRM projects are more suited to On Premise solutions and it would be extremely difficult to do these projects online with CRM onlines current limitations.

If Microsoft changed the online version to host servers online and the CRM developers could access the servers then it would be a very compelling argument, a half on line/on premise solution.

Understanding how CRM Online solutions can work

Reading the paper for the first time, I felt it was unusually worded because it highlighted a lot of limitations but portrayed them as benefits

Microsoft Dynamics CRM Online patterns & principles for solution builders

This line jumped out at me

Everybody has felt a little guilty when they wrote some bad code in the past. Well, in Microsoft Dynamics CRM Online, the temptation to write icky code has been removed in a lot of places, especially where it comes to resource utilization.

Thinking about the document it raises some good points because Solution architects will need to design different solutions for CRM Online than they would if their were designing a CRM solution for a CRM on premise.

Developers don’t like being limited but if more CRM Solutions and customizations will be in deployed in the cloud it’s knowledge CRM developers will need to have.  Part of a CRM Developers work practise is to adapt to new versions of CRM and CRM online is a different version to CRM On Premise.

The part of the document I found worrying is the areas it mentions lack of resources which might be available to you.

My experience with CRM performance issues has involved a lot of investigation around infrastructure (networks, resources, etc), SQL database performance (query performance, adding indexes).  Code optimization and database locking investigation.  I will give an honourable mention to the POA table and security configuration as potential causes of poor performance.

Considering the above any investigation would rely heavily on Microsoft support engineers, this is must be a potential concern for any organizations considering large CRM projects online.

These two quotes from the document, which discuss the potential downside of CRM online

no portion of these shared resources are dedicated strictly to the instance running your solution – they’re shared. That means that you must design your solution to accommodate potential scenarios where these resources don’t perform your requests immediately.

Also, be aware that while there are no strict limits on the amount of workflow jobs you can send to the queue, if you or any of your neighbors sharing the resource are using an inordinate amount of resources, you may have a governor placed on your usage

Hard limits with CRM online

Plug-ins 2 minute timeout
SQL 30 second timeout for database transactions
Running workflow jobs Fair use – no specific hard limits, but the resource is balanced across organizations
Direct database access Not allowed

Where the document is really useful is it focuses on how you should construct CRM Online solutions to utilize the strengths of the CRM online offering.

If you have large long running processes then you can create services in Azure to do this work and take the heavy work load, nicely avoiding hitting any of the hard limits set in a CRM Online solution.

I have no experience of CRM Online using Azure so it was interesting to read the methods to  deploy code as

Azure Iaas

Deploy code to IIS in the cloud running in a virtual machine (VM).  The same as hosting a webservice on your own server or usually in a new web application on a CRM server.

Azure PaaS

I’m not quite sure how this works, it seems you don’t configure IIS but just deploy your code and deploy it as a cloud service.  This seems to be more like a windows service (but in the cloud).  The code needs to be written in a certain way to be run a cloud service.

Configuration over code

Microsoft in recent versions of CRM have been steadily improving the no code solutions with improvements giving improved functionality to mobile devices and more customization choice for CRM Online

Code                  GUI Customizations

Javascript     –     Business Rules

Plugins         –      Real time workflows

Managing Storage

CRM online charges by the Gigabyte/per month fee.  CRM Developers need to manage the CRM database size by storing information in other cloud services such as Sharepoint online and azure storage (Microsoft naturally recommend their own products).

The conclusion of white paper

Creating solutions for the cloud is different. It requires thinking about the system architecture in a different way. But making this leap is an imperative for almost anybody selling business or government solutions today. Keeping up with the market requires us to make the necessary adjustments, and allows us to embrace the attendant benefits of building solutions for the cloud.

Initially I thought highlighting the limitations of CRM online was an odd thing to do.  Looking at the document again it’s seems like a good idea because it’s important CRM Developers know the limitations.

Offering advice and techniques to work around these limitations shows you what is possible.  The white paper points to techniques, software and services CRM developers will need to become more familiar with in the future with CRM on line projects continuing to increase in size and complexity.

The increased complexity of CRM online solutions will need developers to create CRM customizations using no code tools such as business rules and real time workflows in conjuction with code deployed and running in Azure services.

This may explain the raft of new synchronization enhancements added into CRM 2015 SP 1, which I talked about in the blog post below

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

The white paper won me round in the end, highlighting ways around some of the major limitations with CRM online.

Many CRM Developers will have no experience of deploying code in azure and consuming it within CRM.  I would say not just CRM developers but many CRM resellers won’t have experience of creating solutions using code deployed in azure.

This were my thoughts on CRM online, please leave your thoughts, experiences in the comments

CRM 2013 – Let XRM.Utility.OpenEntityForm open CRM forms for you

I wrote a blog post about creating a creating a new record with Javascript and then opening this new record by dynamically creating a url and then some problems I had with that and whilst reading about my trials and tribulations with JavaScript and bugs,  Brian Bayes sat me down (virtually), gave me a cup a tea and said “Hosk, stop all this hurrying and scurrying around, creating dynamic urls, why don’t you just use my good buddy Xrm.Utility.openEntityForm to do all that tricky stuff” and then gave me one simple line to do the method I had written.

Brian didn’t actually use those words but left me  a comment in linkedin saying this function would have have help but that wouldn’t have been as amusing.

So I looked into Brian’s suggetion and by gum he was right.

http://msdn.microsoft.com/en-us/library/72a66f93-92df-42b9-a8fd-b6125c7fe83b#BKMK_OpenEntityForm

Initially I thought it was only available in CRM 2013 but they snuck it in during CRM 2011 rollup 8, which shows you the benefit of reading what useful things are in the rollups.

Xrm.Utility.openEntityForm(“account”,GUID)

http://msdn.microsoft.com/en-us/library/72a66f93-92df-42b9-a8fd-b6125c7fe83b#BKMK_OpenEntityForm

You can also pass in parameters you want to set on the form

var parameters = {};
parameters["formid"] = "b053a39a-041a-4356-acef-ddf00182762b";
parameters["name"] = "Test";
parameters["telephone1"] = "(425) 555-1234";
Xrm.Utility.openEntityForm("account", null, parameters);

The Xrm.Utility object provides a container for useful functions not directly related to the current page. This object was added in Microsoft Dynamics CRM 2011 Update Rollup 8.

var newWindow = Xrm.Utility.openEntityForm("contact");
newWindow.moveTo(0,0);
newWindow.resizeTo(800,600);
  • e helped you here?47m ago
  • Ben HoskingBen Hosking Everyday is a school day. Although the project I was working on was CRM 2011 so I’m not sure that would have worked.44m ago

  • Brian BayesBrian Bayes Ah I see, Xrm.Utility has been tucked away since CRM 2011 Rollup 8 and I only discovered it a couple of months ago to be honest.32m ago

  • Ben HoskingBen Hosking knowing that would have saved me at least an hour mucking about with the bug and getting the url correct. Great comment, cheers.

CRM 2013 Plugin – Step by Step guide for a Post Account Create Plugin using the Developer Toolkit

In the I have created a video if you want to watch me go through the process of creating the plugin. Before I start with this plugin tutorial, to understand it you will need to have gone through my previous tutorials I have three CRM videos and two blog posts

Setting up Developer Toolkit for Microsoft Dynamics CRM

blog – Setting up visual studio with the developer toolkit

video – CRM 2013 – Create a simple plugin in CRM 2013 using the CRM Development Toolkit 

blog – CRM 2013 – simple update plugin

CRM 2013 – Simple Plugin – Redeploying, improving and updating

So I will assume you have got CRM development toolkit setup and ready to rock, so now we can just focus on creating a new plugin to run on the create of an account record In this plugin we are going to create a plugin which is triggered when a new account is created.

Here is a video going through the steps

below features the steps and the code

The plugin will fire after the new account is created so it will be a post plugin message.

The plugin will then create a follow up task with a due date in two weeks time.

Open up your Visual Studio project.

Go to the CRM Explorer

click on Account right click and choose Create Plug-in

Create Account Plugin

 

For the Create Plugin Details, Account is already set but you want to

change Message to Create

Pipeline stage to Post-Operation

Create Account Plugin 1

 

This will Create a file called PostAccountCreate.cs  For this plugin I have split up the default plugin code and the code which does the creating of the task.

 

// <copyright file="PostAccountCreate.cs" company="Microsoft">
// Copyright (c) 2014 All Rights Reserved
// </copyright>
// <author>Microsoft</author>
// <date>4/26/2014 10:42:26 PM</date>
// <summary>Implements the PostAccountCreate Plugin.</summary>
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
// </auto-generated>
namespace HoskCRMDev2013.Plugins
{
 using System;
 using System.ServiceModel;
 using HoskCRMDev2013.Plugins.Plugin_Code;
 using Microsoft.Xrm.Sdk;

 /// <summary>
 /// PostAccountCreate Plugin.
 /// </summary>
 public class PostAccountCreate: Plugin
 {
 /// <summary>
 /// Initializes a new instance of the <see cref="PostAccountCreate"/> class.
 /// </summary>
 public PostAccountCreate()
 : base(typeof(PostAccountCreate))
 {
 base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "account", new Action<LocalPluginContext>(ExecutePostAccountCreate)));

 // Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
 // You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
 }

 /// <summary>
 /// Executes the plug-in.
 /// </summary>
 /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
 /// <see cref="IPluginExecutionContext"/>,
 /// <see cref="IOrganizationService"/>
 /// and <see cref="ITracingService"/>
 /// </param>
 /// <remarks>
 /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
 /// The plug-in's Execute method should be written to be stateless as the constructor
 /// is not called for every invocation of the plug-in. Also, multiple system threads
 /// could execute the plug-in at the same time. All per invocation state information
 /// is stored in the context. This means that you should not use global variables in plug-ins.
 /// </remarks>
 protected void ExecutePostAccountCreate(LocalPluginContext localContext)
 {
 if (localContext == null)
 {
 throw new ArgumentNullException("localContext");
 }

 // TODO: Implement your custom Plug-in business logic.
 // Obtain the execution context from the service provider.
 IPluginExecutionContext context = localContext.PluginExecutionContext;
 IOrganizationService service = localContext.OrganizationService;

 // The InputParameters collection contains all the data passed in the message request.
 if (context.InputParameters.Contains("Target") &&
 context.InputParameters["Target"] is Entity)
 {
 // Obtain the target entity from the input parmameters.
 Entity entity = (Entity)context.InputParameters["Target"];
 if (entity.LogicalName == "account")
 {
 if (context.MessageName.ToUpper() == "CREATE")
 {

 AccountCreateFollowUp accountCreateFollowUp = new AccountCreateFollowUp();
 accountCreateFollowUp.CreateAccountTask(service, entity);

 }
 }
 }
 }
 }
}

The code above checks to see if the entity is of type account and if the message is a CREATE message. This is in case you had the same plugin being fired on lots of different account messages (e.g. create, update, status change).  We aren’t really using it in this plugin but I thought it would be interesting to mention it.

The code which creates the task is called here

AccountCreateFollowUp accountCreateFollowUp = new AccountCreateFollowUp();
accountCreateFollowUp.CreateAccountTask(service, entity);

Below you can see the class which creates the followup task

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;

namespace HoskCRMDev2013.Plugins.Plugin_Code
{
 public class AccountCreateFollowUp
 {
 /// <summary>
 /// Code to create account task for new accounts
 /// </summary>
 /// <param name="service">crm service</param>
 /// <param name="accountEntity">entity of the newly created account</param>
 public void CreateAccountTask(IOrganizationService service, Entity accountEntity)
 {
 try
 {

 //create new task for account set in 2 weeks in the future
 Entity contactAccountTask = new Entity("task");
 contactAccountTask["subject"] = "Check new account is happy";
 contactAccountTask["description"] =
 "Make contact with new customer. See if they are happy with service and resolve any issues.";
 contactAccountTask["scheduledstart"] = DateTime.Now.AddDays(14);
 contactAccountTask["scheduledend"] = DateTime.Now.AddDays(14);
 EntityReference entRef = new EntityReference("account", accountEntity.Id);
 contactAccountTask["regardingobjectid"] = entRef;

 // Create the task and this should be linked to the new account record
 service.Create(contactAccountTask);

 }

 catch (FaultException ex)
 {
 throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
 }
 }

 }

}

Now right click on CRMPackage

click build

Click Deploy

 

CRM 2013 – Exporting your changes in a solution from your CRM 2013 trial

I have had my CRM 2013 trial for a month and those of you who jumped on board on Hosk’s CRM Dev youtube channel will also have also created a CRM 2013 trial which will be expiring soon.  It would be nice if Microsoft could just give me a CRM 2013 organisation to use, particuarly as I mainly use it answer Forum questions and to test CRM and write blogs on CRM 2013 functionality.  Still I’m sure there are a lot of people who would like that but I like everyone else have to create a new CRM 2013 trial every time my current ones runs out days

Here is the video, where I run through the steps of exporting your solution

http://youtu.be/njq9kMbpxsc

Usually Microsoft send you some emails saying your trial is ending soon, you better act quick because all your data and changes will soon be deleted, unless you give Microsoft some money and sign up for a minimum 5 user monthly license and a years contract (I think these details are correct)

The good news is you can just create another trial and in the past my CRM 2013 Trial was still accessible up to 60 days later but it might become accessible any time after 30 days, so we need to act now to save our customization’s from being sucked away.

 Visual Studio

You code components are usually safe from the trail ending.  The reason they are safe is because they will probably be offline in your CRM 2013 Developer toolkit, so you have an offline backup of these file and the ability to import them into a new solution.

The plugins in a solution are an interesting limbo point because in solutions plugins are compiled DLL’s, which is great for moving between CRM organisation, if you want to change those plugins you will need the class files and the code logic (although I do appreciate you can decompile dll’s, its not something you want to be doing often).  So you do need to keep track of your Visual studio CRM 2013 Developer solutions and projects.

Exporting your solution

Open your solution in CRM and make sure you have all the components you have changed or want to take to your new CRM 2013 Trial

Click on components and this will show you all the components that are currently in your solution

solution export 1

anything you don’t want select and click the remove button.

There may be things you have edited in the default solution, if you want those then you need to click the add existing component and select that component.

 

When  you are happy click the Export Solution button.

It will ask you to publish customizations, if you have changes saved but not published you should publish those changes because you cannot export any save but not published changes.

click next

now you will see a list of dependent components, these are components that must exist in the target system to work and the reason for this is because they are referenced in the components in your solution.  An example is Contact is a required component in my solution because there is a contact lookup on the account called Primary Contact.

solution export 2

 

In my example I know all these required components will exist in my next CRM system because they are all default components but if you may need to add some custom ones if you had added them and they don’t exist in your current solution.

Press Next

It asks you if you want to bring the system settings with you?  This depends if you have changed any

Press Next

You now have to choose managed and unmanaged.  If you are not sure export both solutions (it means you will have to run the export wizard again).

I view managed and unmanaged as

managed = Read Only

Unmanaged = Editable

if you export a managed solution it means you won’t be able to modify that code on the target CRM organisation.  This is usually for a customer release.

In my example I want an unmanaged solution because I want to be able to edit and change the components in the next CRM instance I import them into.

 

Data

If you have changed the data in your CRM system and want to bring it with you to the next CRM organisation then  you need to do an advanced find, select the records you want and then export those records into Excel.

Don’t tick the allow for remimport button we want to import this data into a new CRM organisation so there is no point getting the guids because they won’t exist in my new CRM trial.

 

Backing up

It’s a good idea to back up your Solutions as Managed and unmanaged.  I would advise you to keep a backup of all the solutions you create, particularly changes in version format.  Solutions provide a great way to backup custmoziation and allow you to quickly import component changes without having to import new/old data

 

So now you have an export of your changes in a solution ready to import into your next CRM 2013 trial, where you can continue to learn about CRM Development and try the new CRM 2013 features.

 

 

CRM 2013 – MB2-703 – Customization and Configuration Certification Solution Test Questions

The best way to prepare for an exam, is to take practice questions and test your knowledge with questions in a similar way the exam will.

I have created a YouTube video where I go through the questions and explain the answers, I would definitely recommend watching that for the first time at least

http://youtu.be/JKmvKLxJvfY

So with this in mind I have created some questions for you.

I have also created the questions as slides, which you have seen in the video

Multiple choice questions

http://www.slideshare.net/hoskinator/hosks-mb2703-solution-question

Quickfire Yes/No Questions

http://www.slideshare.net/hoskinator/hosks-solution-quick-fire-question

 

HOSK’S TEST SOLUTION QUESTIONS

 

  1. Which statements are true about solutions?
    1. Saving your changes in a solution is mandatory
    2. It’s possible to export the Default Solution
    3. You cannot create more than 50 solutions
    4. Publisher is a mandatory field on a solution
  2. Which components can be added to a solution
    1. Team
    2. Message
    3. Business Rule
    4. Business Unit
  3. Which components cannot be added to a solution
    1. Subject
    2. Service Endpoint
    3. Goal
    4. Site Map
  4. What is true about solutions
    1. Deleting an unmanaged solutions doesn’t delete the components if there is data for them.
    2. Deleting a managed solutions deletes the components and the data
    3. You can only export the default solution as an unmanaged solution
    4. You can add plug-in assembly to a solution
  5. What is development and not customization or configuration from the list below
    1. Create a plug-in to run on the creation of an account to set reference number
    2. Create a custom entity to hold venue information
    3. Javascript validation on a phone number field
    4. Creating a business rule to disable a field until another field has a value
  6. What is removed when you delete an unmanaged solution in CRM 2013
    1. Just the solution record
    2. The solution record, the components and all the data
    3. The solution record and the components
    4. The solution record, it’s components and dependant components.
  7. What does the Version number show
    1. major.build.minor.revision
    2. major.revision.build.minor
    3. major.minor.revision.build
    4. major.minor.build.revision
  8. you import a managed solution which contains the account entity, you then import an unmanaged solution which also contains the account entity, both solutions change the Account Number field to have a different name, what name is on the account form
    1. Account Number, you cannot change the name of the account number
    2. The name given to Account number in the managed solution
    3. The name given to the Account Number in the unmanaged solution
    4. The name given in the solution which was imported last
  9. Which of the below is true
    1. You cannot export the Default Solution
    2. You can export the Default Solution from CRM OnPremise to CRM Online
    3. You need a special security privilege to import solutions
    4. Unmanaged solutions have to be published
  10. What is false about managed solutions
    1. Managed solutions can only be changed or altered by the publisher
    2. importing a managed solution is automatically published
    3. Managed solutions have versioning, unmanaged solutions do not.
    4. managed solutions are additive, you cannot remove any components by importing a managed solution

 

 

 

Answers

  1. b,d
  2. b,c
  3. a,c
  4. b,c,d
  5. A,C
  6. A
  7. D
  8. D
  9. C, D
  10. C

 

HOSK’S QUICKFIRE QUESTION (YES/NO)

 

  1. Can you export a managed solution
  2. Can you export an unmanaged solution
  3. Can customization and configuration be used and refer to the same components.
  4. The correct format for version is major.minor.revision.build
  5. Subjects can be added to a solution
  6. There is no limit to the number of solutions you can create
  7. The prefix in the publisher is added before schema name for entities, fields
  8. The changes to components when importing an unmanaged solution cannot be undone
  9. Queues can be added to solutions
  10. managed properties are customizable by default
  11. It’s not possible to export  an unmanaged solution
  12. managed solution must be published after importing

answers

  1. false
  2. true
  3. true
  4. false
  5. false
  6. true
  7. true
  8. true
  9. false
  10. true
  11. false
  12. false

 

 

 

Hosk’s Top CRM 2013 articles of the week 11th April 2014

Here are my friday CRM articles of the week, there have been some great Developers articles this week

but let us start as always with a celebrity thumbs up

Article of the week

As I am a “computer” person various members of my family have been asking me whether they need to change their passwords because of heartbleed

The simple answer is Yes, just do it.  Google and Facebook could have been compromised.  Interestly the banks (UK), amazon and linkedin all seem ok.  The biggest danger is you have probably used the same password all over the place, so if an account is important to you, go change that password.  You should check that the site has updated their code/certificate to patch up the security flaw, otherwise you will have to change the password again later.  Most of the big internet companies have changed their certificate.

This article on the BBC is pretty good
also this page

an in depth article

http://www.troyhunt.com/2014/04/everything-you-need-to-know-about.html

this site has a bit more clear data

“This is not the first defect of its kind and it certainly won’t be the last, but it is one of the more serious faults we’ve seen in recent internet history,” said Mr Lyne.

Name Vulnerable? Patched? Change password?

Amazon

No

No need

Only if shared with vulnerable service

Amazon Web Services

Yes

Yes

Yes

Apple

Not clear

Not clear

Not clear

Barclays

No

No

Only if shared with vulnerable service

eBay

No

No need

Only if shared with vulnerable service

Evernote

No

No need

Only if shared with vulnerable service

Facebook

Yes

Yes

Yes

Google/Gmail

Yes

Yes

Yes

HSBC

No

No need

Only if shared with vulnerable service

If This Then That

Yes

Yes

Will force users to log out and ask them to update

LinkedIn

No

No need

Only if shared with vulnerable service

Lloyds

No

No need

No

Microsoft/Hotmail/Outlook

No

No need

Only if shared with vulnerable service

PayPal

No

No need

Only if shared with vulnerable service

RBS/Natwest

No

No need

Only if shared with vulnerable service

Santander

No

No need

Only if shared with vulnerable service

Tumblr

Yes

Yes

Yes

Twitter

No

No need

Only if shared with vulnerable service

Yahoo/Yahoo Mail

Yes

Yes

Yes

CRM Article of the Week

Here is the CRM article of the week

This article/slideshow was tweeted by Jukka Niiranen and is a fantastic resource for any CRM Developers (like those who are subscribed to Hosk’s CRM Dev)

Developer Tips and Tricks by Marc Schweigert

Is basically a roundup of lots of great sites, great tips and best practices on all areas of CRM development, 33 slides of action packed CRM Developer goodness

 

CRM 2013 Articles

 

DEV Articles

Jukka Niiranen has not only been writing great CRM articles but also tweeting some very useful ones as well.  This article has a video and shows you how to debug your Javascript in Visual Studio

EUREKA: F5 debugging of CRM JavaScript web resources

The linked article from the above but this is amazing, you can debug Web Resources without deploying them by using a Scott Durow trick of using Fiddler 2. AWESOME

Debugging CRM web resources without ever deploying them

It’s not a blog but a youtube video, to whom someone described as the infamous CRM blogger Leon Tribe.  This video in the words of Leon Tribe is “making the world a better place”.  This is a good article for CRM Developers to consider

TFS for Microsoft Dynamics CRM Development Management

I was asked this question on the Hosk CRM Dev linkedin group and then rather marvelously the questioner found the answer and shared it with everyone

Install CRM Developer Tookit in Visual Studio 2013 

Well I couldn’t put articles of the week in without including some of mine surely.  I did another video featuring CRM plugins, I updated the previous weeks example and go into a bit more about plugin theory.  Join Hosk’s CRM Dev channel NOW

CRM 2013 Video – simple update plugin, Redeploying, improving and updating

 

Blog – CRM 2013 – Plugins – Simple update plugin – Redeploying, improving and updating

The blog post for the first Plugin video, a good step by step guide to developing a CRM

CRM 2013 – Step by Step Update Plugin Tutorial using the CRM 2013 Development Toolkit

 

How to connect and authenticate to Office 365 and CRM 2013

MS CRM 2013 Online upgrade to Office 365 authentication

The tip of the quick Dev tip shows how to refresh your web resources with code

Refreshing the Web Resource in CRM 2013

Microsoft like to call it PBL – Portable Business logic, everyone else calls them Business Rules

 Hiding a Tab in Dynamics CRM using Portable Business Logic (PBL)

 

CRM 2013 Articles

Jukka Niiranen who has 657 followers on google plus and no wonder he writes brilliant blog posts using his special CRM MVP powers, here he shows us how to report on the sneaky CRM system entities of Case Resolution and Opportunity closed.

Accessing “Special” Activity Data with CRM Report Wizard

Did you know there are a bunch of Business Process Flows inside CRM just waiting to be turned on? You do now

 How to Turn On Ready-to-Use Business Process Flows in Dynamics CRM 2013

There are three new server roles and services

Dynamics MS CRM 2013 – New Server Roles and Services

Joel Lindstrom the CRM MVP answering Hosk’s questions this week

CRM MVP Question and Answer – Joel Lindstrom

Be careful when you check some options on entities because like taking the Red pill in the matrix you can never go back

Tip #110: Don’t prematurely check the boxes

Common Queries Microsoft Support answer about CRM Async service, it’s a cheeky look under the covers

Common queries regarding Dynamics CRM Asynchronous Service

A Hosk blog reader asked me some questions about starting a CRM blog, my advise was do it, you will learn a bunch of stuff about CRM and you might help other people who want to know about CRM.  So she did and here is her first CRM blog, well done  Elaiza

I’m a CRM tourist, I need a tour guide!

 

CRM 2013 – Plugins – Simple update plugin – Redeploying, improving and updating

I recently did a YouTube video which stepped through the process of creating a simple CRM 2013 plugin which ran on the update of the account entity.

The purpose of the video was to step through the process of creating a plugin and with that in mind I wanted to create the simpliest plugin I could think of.  Once you can do the process of creating a simple plugin and deploying it, it’s then a case of adding in your own logic and doing the process yourself.

In the first video – CRM 2013 – Create a simple plugin in CRM 2013 using the CRM Development Toolkit I explained some of the fundamental logic of a plugin (extending the IPlugin interface, the all important Execute method etc).  I also wanted to show how useful the CRM Developer toolkit was, particularly when it comes to creating and deploying plugins because it does a lot of the hard work for you.

I wanted to continue the journey of learning about plugins but without doing too much new code but I still wanted to add some new code so it’s interesting.

So I created a new video

CRM 2013 – simple update plugin, Redeploying, improving and updating 

This video updates the previous basic update plugin and this time I only trigger the plugin when a certain field Account Rating gets changed.  This is important thing to consider in update plugins, particularly in these days of autosaving.  Only trigger the plugin to run if certain fields are triggered, this will save server resources by not firing your plugin every 30 seconds.

It’s amazing the things you learn whilst writing blogs and recording videos.  I didn’t previously know how you deleted plugins using the CRM Development toolkit, so I started sniffing about and then worked out how to.   Below I run through changing the fields which trigger the account pre update plugin

Go to the CRM Explorer

You will notice the green plugins are the plugins in the solution you are in

nudge the down arrow and you can see the plugin steps

Update plugin 1

Edit the plugin step

Update plugin 2

The CRM Developer toolkit also allows you to delete the plugin or plugin steps, useful stuff

In the video – CRM 2013 – Simple update plugin – Redeploying, improving and updating I also run through a couple of important plugin concepts.

What’s passed into a plugin

The CRM 2013 SDK is a great document but a bit dry and difficult to get you started but once you are up and running there are lots of great explanations of how things work, this page is very useful for people writing plugins

Understand the Data Context Passed to a Plug-In

It explains what is actually passed into the plugin, the ServiceProvider has lots of goodies in like

IPluginExecutionContext

This has lots of data in like the user who triggered the plugin

IOrganizationService

Use this to access CRM and Create, Read, Update and Delete CRM records

context.InputParameters and context.OutPutParameters

The input parameters hold a collection and in that collect is the Target entity object, this has the values changed from the account update

there is also the tracing object

 

In the example I am going to use all three of these item and in most plugins you will use them but the page also has this table which explains what objects are passed into the context.InputParameters because it’s not always the Target object you should look for.  The picture below is a screenshot from the page

Update plugin 3

So what you should understand from the table above is, when a record or action triggers a plugin then usually either the entity is passed into the context.InputParameters or it’s an EntityReference.  You usually retrieve and cast this object out and then pass this to your plugin logic.

The one that used to catch me out was SetStateRequest passing the EntityMoniker.  What happened to me was I copied my boilerplate plugin code and I couldn’t understand why it wasn’t going into the code and running.  The reason was I was checking to see if the Target existed and if it did casting it to an entity and passing that into another method to do the work but it never went into my code.

So I had to debug the code to find there was no Target! finally I found the oddly named EntityMoniker and I worked out what to do from there.

 

 Plugin Stages

In the first plugin I couldn’t remember what the stages of a plugin were and their significance, all I could remember was they were linked to the database transaction and something about numbers going up in 10.

So I have done my homework and once again found some great information in the CRM 2013 SDK

event execution pipeline

The page has an interesting overview of the whole CRM architecture and it simplifies the stages
PRE-EVENT
PLATFORM CORE
POST-EVENT
The picture below is a screen from the Event Execution Pipeline page
Update plugin 4

As you know from registering plugins we can only register plugins

Pre-Validation – 10

Pre-Event – 20

Post-Event -40

The actually database transaction finishes in step 30 – Platform core operation and you can interfere with this, this is where the system plugins will run and kick off and updating system values and triggering other things.

An interesting point is the Pre-Validation, this is triggered before security checks have happened, so before CRM has checked the user can update the record maybe, basically before CRM checks the security roles and the PrincipalObjectAccess table (where all the security stuff is stored for users) is checked.

So that is the end of my quick plugin theory lesson and back onto the code, So along with the changing the plugin filter records (which you can see the RegisterFile.crmregister) I changed the code.

I now want to trigger the update on the change of AccountRating and I am going to read the value, which those of you who watched the video will know, OptionSetValue’s in CRM are held as ints.  CRM also holds Metadata on the OptionSet which holds the text.

My code is going to run based on the Int value because I think maybe in the future people might change the text in the OptionSet from Gold, Silver, Bronze to 1, 2, 3 or Great, OK, Rubbish.

I also get the guid of the user (entity SystemUser)who triggered the plugin by updating the AccountRating field.  This value is passed in with the plugin context and can be retrieved

Guid userId = context.InitiatingUserId;

There are two different user guid passed into the context and you should know which is which

context.initiatinguserid: the systemuser GUID who actually triggered the plugin
context.userid : gets the impersonated systemuser GUID

In my case I want the user who triggered the plugin

I then lookup the fullname and domainname of the user because this is more useful than a guid to end users but the guid is great for retrieving more data about that record.  I use the IOrganisationService to retrieve more fields from the record.  To do this all I need is the entity logical name, guid and the fields I want to retrieve

Entity userName = service.Retrieve(“systemuser”, userId, new Microsoft.Xrm.Sdk.Query.ColumnSet(new[] { “domainname”, “fullname” }));

Then it’s a case of concatenting them into string and adding this to the account entity being updated.

The full code is below

 

// <copyright file="PreAccountUpdate.cs" company="Microsoft">
// Copyright (c) 2014 All Rights Reserved
// </copyright>
// <author>Microsoft</author>
// <date>4/3/2014 12:04:45 AM</date>
// <summary>Implements the PreAccountUpdate Plugin.</summary>
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
// </auto-generated>
namespace HoskCRMDev2013.Plugins
{
using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;

/// <summary>
/// PreAccountUpdate Plugin.
/// Fires when the following attributes are updated:
/// All Attributes
/// </summary>
public class PreAccountUpdate: Plugin
{
/// <summary>
/// Initializes a new instance of the <see cref="PreAccountUpdate"/> class.
/// </summary>
public PreAccountUpdate()
: base(typeof(PreAccountUpdate))
{
base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Update", "account", new Action<LocalPluginContext>(ExecutePreAccountUpdate)));

// Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
// You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
}

/// <summary>
/// Executes the plug-in.
/// </summary>
/// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
/// <see cref="IPluginExecutionContext"/>,
/// <see cref="IOrganizationService"/>
/// and <see cref="ITracingService"/>
/// </param>
/// <remarks>
/// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
/// The plug-in’s Execute method should be written to be stateless as the constructor
/// is not called for every invocation of the plug-in. Also, multiple system threads
/// could execute the plug-in at the same time. All per invocation state information
/// is stored in the context. This means that you should not use global variables in plug-ins.
/// </remarks>
protected void ExecutePreAccountUpdate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}

// TODO: Implement your custom Plug-in business logic.
// Obtain the execution context from the service provider.
IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;

// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["Target"];
string entityDescription = "HOSK CRM DEV FIRST PLUGIN HAS RUN AND UPDATED THE DESCRIPTION";

//accountratingcode
if (entity.LogicalName == "account")
{

try
{
if (entity.Attributes.Contains("accountratingcode"))
{
Guid userId = context.InitiatingUserId;
Entity userName = service.Retrieve("systemuser", userId, new Microsoft.Xrm.Sdk.Query.ColumnSet(new[] { "domainname", "fullname" }));
string fullname = (string)userName.Attributes["fullname"];
string domainName = (string)userName.Attributes["domainname"];
entityDescription = "user " + fullname + "has the domain name of " + domainName;
entityDescription = entityDescription + Environment.NewLine + DateTime.UtcNow.ToString();
OptionSetValue accountRatingCode = (OptionSetValue)entity.Attributes["accountratingcode"];
if (accountRatingCode.Value == 1)
{
entityDescription = entityDescription + Environment.NewLine + "account rating = gold";
}
else if (accountRatingCode.Value == 100000000)
{
entityDescription = entityDescription + Environment.NewLine + "account rating = silver";
} else {
entityDescription = entityDescription + Environment.NewLine + "account rating = bronze";
}

if (entity.Attributes.Contains("description"))
{
//string entityDescription = (string)entity.Attributes["description"];
//entityDescription = "HOSK CRM DEV FIRST PLUGIN HAS RUN AND UPDATED THE DESCRIPTION";
entity.Attributes["description"] = entityDescription;
}
else
{
//entityDescription = "HOSK CRM DEV FIRST PLUGIN HAS RUN AND UPDATED THE DESCRIPTION";
entity.Attributes.Add("description", entityDescription);
}

}
}

catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
}
}
}

 

CRM 2013 – Workflow to set the current date and time

This question has popped up in the forums now and again so I thought I would write a blog post on it.

The solution on how to do this is simple, once you know where to look and how it works.  I can understand why some people struggle to find the answer to the question of setting a date field to the current date and time because you don’t see it mentioned very often and it isn’t obvious.

To set the a Date Time value in CRM to a when the workflow was run you can use the dynamic value

Process

Execution Time

This basically does what is says on the tin and sets a Date time value to Execution time of the workflow.

workflow for current date and time

Open up your workflow and choose the Update, select Account entity

To set a field

Select the field and in the example above, I clicked into the Account Date Field

In the look for I scrolled down to Process (it’s right at the bottom)

in the next field select Execution Time

Press OK

You will see the Account Date Field will now have a highlighted value.

Save and Close

Activate the workflow

CRM 2013 Video  Workflow to set date and time field and user when the primary contact on an account is changed

Awesome picture from here

CRM 2013 – Step by Step Update Plugin Tutorial using the CRM 2013 Development Toolkit

I will go through the process of creating a basic plugin today using the CRM 2013 Developer Toolkit and CRM 2013 Online, which in my case is a trail.

STEP BY STEP VIDEO

I created a video to go through creating a simple plugin, which I recommend you watching but I have also go through the steps in a blog post because you might want to reference the steps later without watching the video (e.g. YouTube might be blocked at work).  I would also add there is a lot more explanation in the video than on the blog post.

CRM 2013 – Create a simple plugin in CRM 2013 using the CRM Development Toolkit

 

I would recommend looking at the CRM 2013 SDK because it is very useful and documents what all the options available.   The reason I made this blog post and Hosk’s CRM Dev YouTube channel is The CRM 2013 SDK is a great resource but can be a little bit difficult to get started with but hopefully with the blog post and the video I will make it easier for you.

This video will a bit of plugin theory (the blog will just contain the steps to create and deploy the plugin) and I will try and explain what we are doing and practical because I will go through the process of creating and deploying the plugin, step by step.

You should have already watched these videos and are at the stage where you have CRM 2013 Developer Toolkit setup and pointing at your CRM 2013 organisation.  If not watch the videos below

Created your CRM 2013 Trial

Blog Setup the CRM 2013 Developer Toolkit

Video step by step guide to setting up the CRM 2013 Developer Toolkit

Blog – Setup and understand Solutions

Video – CRM 2013 – Understanding Solutions and how they work in CRM 2013 

Now it’s time to create a very simple plugin

Open Visual studio, you should have already setup the Visual Studio Developer toolkit, I created a package as shown in the picture below

setup CRM dev toolkit 1

 

This will Create a package, I removed the workflow project so I am just left with CrmPackage and Plugins projects

Create Plugin 7

The important files above are the

RegisterFile.crmregister

This RegisterFile.crmregister is a file which holds the plugin registration data any plugins created in your CrmPackage.  The details are then used to deploy plugins to CRM

Plugin

This is a default file created by the CRM 2013 Development Toolkit.  When you create a plugin, it will extend the Plugin class and use it as a base.   The Plugin class uses the IPlugin interface and has the important Execute methods which all CRM plugins must have and this is the main method called.

 

CRM Solution

Make sure you connected to the correct CRM organisation and you have specified the correct Solution, so when you deploy your plugin it will be included in the correct solution.

You can check this by going to

Tools –> Connect to Dynamics CRM Server

Press the Log on button and then you will be able to select an organisation value and a solution

Create Plugin 0

CREATE A PLUGIN

To create a plugin open the CRM Explorer

Entities

Select Account

Right click and choose Create Plugin 

Create Plugin 4

The Create plugin screen will be displayed.

Below I am creating a plugin to run on the update of the account entity

Create Plugin 1

 

The Create Plug-in dialog box appears with the fields in the following table.  This information was taken from the CRM 2013 SDK

http://msdn.microsoft.com/en-us/library/hh547400.aspx#BKMK_CreateAndDeploy

  1. Field Description
    Project The plug-in library project in your Visual Studio solution.
    Class A recommended class name based on the selected pipeline stage and message.
    Primary Entity The entity that must be processed by the execution pipeline for the plug-in to execute.
    Secondary Entity Some messages require a secondary entity. See the documentation on the specific message for more information.
    Message The message that must be processed by the Microsoft Dynamics CRM execution pipeline for the plug-in to execute.
    Filtering Attributes A list of entity attributes that cause the plug-in to execute when it is changed. A value of null causes the plug-in to execute if any of the attributes change. When you specify a message that supports filtering attributes, for example Update, an ellipsis (…) button is displayed that lets you select attributes from a list.
    Run in Context Specify the system account that owns any data changes the plug-in makes. The Calling User is the logged on user who initiated the message to be processed. For more information, see Impersonation in Plug-Ins.
    Execution Order Specifies the order, also known as rank, that plug-ins are executed in a pipeline stage. Plug-ins registered by using an order value of 1 are executed first, followed by plug-ins registered by using an order of 2, and so on. However, if there is more than one plug-in in a stage with the same order value, the plug-in with the earliest compilation date is called first.
    Pipeline Stage Specifies when you want the plug-in to execute: before (Pre) or after (Post) the core operation that processes the message. For more information, seeEvent Execution Pipeline.
    Deployment Specify where you want the plug-in deployed: on the server, on Microsoft Dynamics CRM for Outlook with Offline Access, or both.
    Execution Mode For plug-ins registered to execute in a post stage, specify if you want them to execute immediately (synchronous) or queued to execute later (asynchronous). For post operations, specifying asynchronous execution gives you improved system performance compared to synchronous execution.
    Description A description of the step. Typically, you can describe the purpose of the step for other developers or administrators who might run the registration tool at a later date.
    Unsecure Configuration If you have written a constructor for the plug-in that takes one or two string arguments, any string values that you specify in these fields are passed to the plug-in constructor at run-time. For more information, see Write a Plug-In.
    Secure Configuration
    Pre Image Alias A pre-image is a snapshot of the entity’s attributes before the core operation. The entity alias value that you specify is used by your plug-in code as the key into the image collection.
    Parameters The list of attributes to be include in the pre-image.
    Post Image Alias A post-image is a snapshot of the entity’s attribute after the core operation. The entity alias value that you specify is used by your plug-in code as the key into the image collection.
    Parameters The list of attributes to be include in the post-image.

 

After you have finished selecting the choices for the plugin and press the OK button, a  new file called PreAccountUpdate.cs will be created in the Plugin project.  This will extend the Plugin class (a class created by the CRM 2013 Development Toolkit) and there will be a section for you to put in the code you want to execute in the plugin.

The Development Toolkit will also update the RegisterFile.crmregister adding a new line for the account plugin you have added.  Warning if you have this file checked into source control it might not editable and you will get an error because the Development Toolkit will try to update the RegisterFile.crmregister but won’t be able to because it’s read only.

You will notice the guid values in the RegisterFile.crmregister are all 0000, this because proper guid values will be created when you register the plugin in CRM, at the moment the plugin does not exist in CRM yet. Below is the RegisterFile with the plugin that has been deployed so the guids have values.


<?xml version="1.0" encoding="utf-8"?>
<Register xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/crm/2011/tools/pluginregistration">
<Solutions>
<Solution Assembly="HoskCRMDev2013.Plugins.dll" Id="df794508-c1ba-e311-9d03-d89d6765d360" IsolationMode="Sandbox" SourceType="Database">
<PluginTypes>
<Plugin Description="Plug-in to PreAccountUpdate" FriendlyName="PreAccountUpdate" Name="HoskCRMDev2013.Plugins.PreAccountUpdate" Id="e2794508-c1ba-e311-9d03-d89d6765d360" TypeName="HoskCRMDev2013.Plugins.PreAccountUpdate">
<Steps>
<clear />
<Step CustomConfiguration="" Name="PreAccountUpdate" Description="Pre-Operation of Account Update" Id="d507df0f-c2ba-e311-bb7d-d89d6763fc38" MessageName="Update" Mode="Synchronous" PrimaryEntityName="account" Rank="1" SecureConfiguration="" Stage="PreInsideTransaction" SupportedDeployment="ServerOnly">
<Images />
</Step>
</Steps>
</Plugin>
</PluginTypes>
</Solution>
</Solutions>
<XamlWorkflows />
</Register>
<pre>

 

Sign the Plugin

All plugins in CRM 2013 must be signed.  You do this by

Right Clicking the Plugin Project

Go to the Signing Tab

tick the Sign Assembly checkbox

look up an existing Key or create a new one 

You don’t need to set a password if you don’t want to

save the changes and close the Plugin Properties page

Create Plugin 2

Create the Plugin Code

I am creating a very simple plugin, all it does it update the Description field on the account form when the account update is triggered, which will be 30 seconds because this will be triggered by the CRM 2013 autosave feature.

If the Description has been changed we overwrite it and if it hasn’t we add the description field

I am going to write this value

"HOSK CRM DEV FIRST PLUGIN HAS RUN AND UPDATED THE DESCRIPTION"

Create Plugin 3

 

namespace HoskCRMDev2013.Plugins
{
using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;

/// <summary>
/// PreAccountUpdate Plugin.
/// Fires when the following attributes are updated:
/// All Attributes
/// </summary>
public class PreAccountUpdate: Plugin
{
/// <summary>
/// Initializes a new instance of the <see cref="PreAccountUpdate"/> class.
/// </summary>
public PreAccountUpdate()
: base(typeof(PreAccountUpdate))
{
base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Update", "account", new Action<LocalPluginContext>(ExecutePreAccountUpdate)));

// Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
// You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
}

/// <summary>
/// Executes the plug-in.
/// </summary>
/// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
/// <see cref="IPluginExecutionContext"/>,
/// <see cref="IOrganizationService"/>
/// and <see cref="ITracingService"/>
/// </param>
/// <remarks>
/// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
/// The plug-in’s Execute method should be written to be stateless as the constructor
/// is not called for every invocation of the plug-in. Also, multiple system threads
/// could execute the plug-in at the same time. All per invocation state information
/// is stored in the context. This means that you should not use global variables in plug-ins.
/// </remarks>
protected void ExecutePreAccountUpdate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}

// TODO: Implement your custom Plug-in business logic.
// Obtain the execution context from the service provider.
IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;

// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["Target"];

if (entity.LogicalName == "account")
{
string entityDescription = "HOSK CRM DEV FIRST PLUGIN HAS RUN AND UPDATED THE DESCRIPTION";
try
{
if (entity.Attributes.Contains("description"))
{
//string entityDescription = (string)entity.Attributes["description"];
//entityDescription = "HOSK CRM DEV FIRST PLUGIN HAS RUN AND UPDATED THE DESCRIPTION";
entity.Attributes["description"] = entityDescription;
}
else
{
//entityDescription = "HOSK CRM DEV FIRST PLUGIN HAS RUN AND UPDATED THE DESCRIPTION";
entity.Attributes.Add("description", entityDescription);
}
}

catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
}
}
}

 

 DEPLOYING THE PLUGIN

Now you have finished writing the code, it’s time to deploy the plugin in CRM.  Your user will need to be a CRM Administrator.  If you are deploying plugins which are not in sandbox Isolation mode then you will also need to be a Deployment Administator.

As I am deploying to CRM 2013 online then the plugin has to be only a CRM Administrator because the plugin has to be in sandbox isolation mode.

Right Click on CrmPackage

Press the Deploy button

You will either get an error or it will have worked.  Often when it has worked it will inform you the RegisterFile.crmregister file has changed, this is CRM 2013 Developer Toolkit updating the file with Guid’s for the plugins.

Create Plugin 8

Check the plugin has been registered in the CRM organisation\database by looking at the CRM Explorer and checking in the Plug-in Assemblies section, you should see your new plugin highlighted in green

Create Plugin 5

You can also check by opening your Solution and looking in the plugin assembles section.

Create Plugin 6

 

I hope you subscribe to Hosk’s CRM Dev youtube channel where I will be going through the lots of different ares of CRM 2013 Development, this is useful for people who are starting out CRM Development, Developers who haven’t used CRM 2013 yet or just CRM Developers.

I am also studying for the MB2-703 – CRM 2013 Customization and Configuration exam and have a playlist with those videos

https://www.youtube.com/playlist?list=PLsOVDEkdRUuyY0xRq8flZ-ePOcBvZ-XpJ