Tuesday, September 19, 2017

Improve Dynamics 365 and submit your ideas

Microsoft recently setup a new channel to submit your ideas to improve Dynamics 365 – go check it out on https://ideas.dynamics.com/ . Some development teams at Microsoft, definitely take the feedback formulated through this new channel to heart.  During one of the Dynamics 365 Spring 2017  Preview executive briefing sessions one of the presenters told us  “If you look at the new “Social pane” section you will notice that out of the top 10 ideas, 6 are currently addressed in the new Activity timelines in Dynamics 365”.  But also one of the things that we bumped into when doing a project with Dynamics CRM Online Portals – the fact that Plugin exception information needs to be surfaced in Dynamics CRM Online Portals was recently picked up the Portal team (thanks

So go ahead and submit your own ideas for improvement and don’t forget to vote for these ideas:

Thursday, September 14, 2017

Dynamics 365 monthly reading September 2017

Technical topics (Configuration, customization and extensibility)
Topics for Dynamics 365 business analysts, power users and end users

Topics about Dynamics 365 Spring release (aka 9.0 release)
The Dynamics 365 Spring release (version number 9.x) is the next upcoming release of Dynamics 365. For the moment we only got news about the updates for the next version of Dynamics CRM/365 online so no news yet for on-premise deployments.
Technorati Tags: ,,

Friday, August 25, 2017

Dynamics 365, Azure webjobs, Azure Service Bus queues and deadletters

When you need to integrate Dynamics 365 (online) with other applications/services in on premise or in the cloud there are a number of challenges. One of the most commonly used integration patterns is messaging since it allows for loose coupling and it provides a reliable way of integration since both applications don’t necessarily have the same responsiveness or uptime. One of the key extensibility points from an integration perspective that you can leverage is the fact that you can connect Microsoft Dynamics 365 (both on premise and online) with the Azure Service  (See Azure integration with Dynamics 365). In an asynchronous messaging pattern, you will however still need a message processing component.  Since you are already leveraging cloud components, it might make sense to also use Azure for this message processing component.


There a number of Azure components you might take a look at:
  • Azure cloud services: use an Azure worker role for message processing (for some background on this read Should I use cloud services or something else?)
  • Azure app services: use  Azure web jobs for message processing.
  • Azure virtual machine hosting the processing components
  • Azure functions  - similar to Azure web jobs since it was built on the same code base as webjobs and has a similar API.
  • Azure logic apps
If you look at the two first options (worker roles and web jobs), you will notice that they offer similar functionality payload – ability to run code repeatedly. However, there are some differences between the two - primarily in terms of environment customization. Web Jobs are good for running small tasks (not very computation heavy) and useful in scenarios where you do not have the need to depend on host OS features. Worker Roles can be used to run computation heavy workloads and their host OS can be modified a bit (by installing dependency components in OS through startup tasks). Worker roles are costly (similar to running a dedicated VM) while web jobs do not carry any additional cost. In case you need extreme customization on OS environment, then you would simply run a windows service inside custom OS image in Azure VM.  So basically you are looking at a trade off between control (and full flexibility) and agility combined with ease of management.



Now, if you look specifically at Azure webjobs, you will see that they can be triggered by a schedule, messages in Azure storage queue or blobs added to Azure storage and http call by calling the Kudu Webjobs API. But given the fact that Dynamics 365/RM already provides integration  with Azure Service Bus, this is the one that you will typically use – for a good walkthrough take a look at  How to use Azure Service Bus with the WebJobs SDK .

One of the things to keep in mind though, is that when an Azure webjob encounters an error in processing a message, it will retry processing it a specified number of times.  The number of retries is configured through the JobHostConfiguration.Queues.MaxDequeueCount property – see Azure webjobs and JobHostConfiguration for more details. This mechanism has been been built to avoid that a queue-based application gets stuck in a loop receiving and aborting the same message it can not process – this is also referred to as poison message handling.  So if this count is exceeded, the message will be move to the deadletter queue (when it is configured).

But the Azure service bus queues also have a property called MaxDeliveryCount (See QueueDescription class) which is by default set to 10 – so if this setting is lower than the setting in the JobHostConfiguration, your message might be moved to the deadletter queue (DLQ) earlier – see Overview of service bus dead-letter queues for more details.
If you open the deadletter queue with Azure Service Bus Explorer you will notice that these messages have additional properties called DeadLetterReason and DeadLetterDescription – these might be helpful in determining what causes the messages to end up in the DLQ. You can also move a message to the dead letter queue yourself by calling the BrokeredMessage.DeadLetter method.

Lessons learned:  If you are building an integration using Azure Service Bus queue, don't forget to think about how to handle messages which are deadlettered.


Technorati Tags: ,,,,,

Sunday, August 20, 2017

Dynamics 365 monthly reading August 2017


Technical topics (Configuration, customization and extensibility)

Topics for business analysts, power users and end users

Thursday, August 10, 2017

Voice of the Customer for Dynamics 365

In March 2015, Microsoft announced the acquisition of Mojo Surveys – a customer feedback solution which was built solely for Microsoft Dynamics CRM (both online and on-premise).  This product was re-engineered and rebranded to Voice of the Customer (VoC). VoC was initially made available in preview in January 2016 – Preview feature: Voice of the Customer surveys and became generally available in the December 2016 release (VoC solution version 8.3.x and higher). At the moment VoC is only available for Dynamics CRM/365 (online) and apparently there are no plans to make it available for integration with on premise Dynamics CRM/365.

Voice of the Customer adds rule-based, multi-channel feedback surveys integrated with workflows, campaigns and e-mails on top of Dynamics 365. These surveys can be used in a range of scenarios from service feedback to focus groups to sales scenarios. Voice of the Customer allows you design and publish surveys from within Dynamics 365, distribute them to your target audience. Respondents can take part in a survey in different ways, depending on how you sent the invitation out, whether you want anonymous or non-anonymous responses and whether you want to integrate data from CRM into the survey. Responses can be incorporated into a business process by creating response routing rules. Voice of the Customer is available for installation as a preferred solution from the Applications tab in the Dynamics 365 Administration center.


From Voice of the Customer version 9.0 onward, you immediately receive a confirmation screen for accepting the license terms and for activating VoC when configuring it from within the Applications tab.




In previous versions, you first had to trigger the installation and afterwards go to the solution and accept the licensing terms from within the solution screen.



In the previous version, you could also Retrigger response processing to troubleshoot when you did not see responses coming in see Where are my Voice of the Customer responses? for more details. It is unclear where this setting has gone in version 9.x and higher.

Before you install the solution it is important to realize that behind the scenes Voice of the Customer uses a number of different Azure components such as Azure blog storage, Azure web and worker roles, Azure Keyvault, Azure SQL  see Install the Voice of the Customer solution for more details about this. These components are subject to other privacy and compliancy governance policies – for more information see Azure Trust Center

It is quite easy to get started with VoC and the steps are thoroughly outlined in Create a Voice of the Customer survey to get customer feedback . In previous version, I noticed that sometimes the survey definition got corrupted so it is important to quite regularly click on “Preview survey”. If you get an error like “Isv code aborted the operation”, it is best to delete the last question that you added, save the survey, run the preview and re-create the survey question.



Other good walkthroughs you can take a look at are A Step by Step Guide to Create Your First Survey with Dynamics CRM 2016 Voice of the Customer as well as Voice of the Customer for Dynamics CRM 2016 (configuration screens have changed a little bit from 9.x onwards but these articles are still worth taking a look at). One of the things, I also liked about the surveys is the fact that they are also mobile-friendly





Wednesday, August 09, 2017

Managed metadata column values not visible in SharePoint view

I recently encountered a problem with views in a SharePoint site collection – the values of the managed metadata column were not visible anymore for most users in the list views. However  when the user edited the item or viewed the details of an item – they could see the value. Apparently this issue was caused as a side effect of migrating Windows users to claim users. For performance reasons, managed metadata (or taxonomy items) are stored at site collection level in a hidden list called TaxonomyHiddenList which is accessible at the root level of a site collection e.g. http://servername/sites/sitecollection1/lists/taxonomyhiddenlist.  The list by default has read access to all Authenticated users but when performing the claims migration the security was mixed up, by giving all authenticated users read permission again, the issue was resolved.


Thursday, August 03, 2017

Free CRMUG Belux webinar – What’s new in Dynamics 365 Spring 2017 release

By now, you have probably all read about the upcoming Dynamics 365 spring 2017 release. If you want to learn more about it register for the free CRMUG Belux webinar – What’s new in Dynamics 365 Spring 2017 release . This June, Microsoft announced the next Dynamics 365 release, called the “Spring 2017” release wave. During a 3-day (!) long preview session, Microsoft’s product team took a deep dive into the new capabilities that are coming to the platform, such as:
  • An updated user interface, providing a uniform experience for users across web, app and mobile,
  • New features in Dynamics 365 Customer Insights that leverage data across and beyond Dynamics CRM and machine learning capabilities (Also check out Introduction to Dynamics 365 Customer Insights to get started)
  • New social selling capabilities, a direct result of the LinkedIn acquisition
  • New features around scalability and extensibility, -
  • The release of the Business Edition, a sales and marketing app triggered towards small and medium businesses.
Your CRM-UG BeLux team has managed to bundle all these exciting announcements in a 1-hour lunch webinar for you on August 28th. Our presenters, Microsoft’s Philip Verlinden and Dieter De Cock, have even promised there will be time for Q&A.

Introduction to Dynamics 365 for Customer Insights (DCI)

Dynamics 365 for Customer Insights (DCI) was introduced in December 2016 and has recently received some interesting updates in the Dynamics 365 Spring update.  DCI is an Azure-based SAAS service which enables organizations to bring together transactional, web and social customer data to visualize it in a Customer 360°. DCI also allows you apply advanced data transformation algorithms (KPI calculation and machine learning) on this data to generate role-specific insights for different roles within an organization. 



The key differentiators within Dynamics 365 for Customer Insights are:
  • It provides a scalable data infrastructure which can handle millions of interactions, entities and relationships between entities. Building such an infrastructure can be a daunting task and will consume a lot of upfront investment in  IT capacity. By providing a platform where you only pay for the data that you need to handle, you will be able to shift investment to resources and more value added tasks such as integrating the intelligence within your existing business processes
  • Out of the box connector for Dynamics 365 for Customer Engagement (CRM) which allows you to rapidly get going starting from the existing effort that you put into building your CRM platform
  • Ability to match customer identities in different systems using conflation algorithms and predictive matching – this allows to merge/cluster customer identities at scale.
  • Built-in advanced machine learning applications such as segmentation – which identifies cohorts of users with the same characteristics or at the same stage of the customer journey – and built-in predictive scoring. Business users will be able to define the business outcome they want to predict (e.g. customer churn = customer for which status becomes inactive) and DCI will automatically create a machine learning model and validate it (behind the scene it will do feature selection, machine learning selection, training and validation,…). Prediction scores will be automatically generated for new entities or they will be recalculated for entities for which one of the signals/characteristics impacting the predictive score will change. This allows you to get up and running quickly with a machine learning solution without hiring data scientists.
  • Extensible platform – ability to ingest data from multiple data source by building your own connectors and ability to expose DCI entities,metrics and predictions through Power BI, Power Apps or using the REST API
Customer Insights is leveraging the same components which are also used within the Cortana Intelligence Solutions but they are taking it a number of steps further by providing out of the box connectors, configurations screens, ingest and egress paths as well as built-in visualize layer. You however have less control on the inner workings of the Customer Insights solution since this is a SAAS solutions whereas most Cortana Intelligence Solutions combine a SAAS, IAAS and PAAS platform components.



One of the customer cases that you should definitely take a look at is Marston’s and Customer Insights - Marston, is a brewing company operating more than 1700 pubs in the UK and was one of the early customers that started using this application.  In order to create a personalized pub experience for their customers and achieve a more targeted marketing they wanted to bring together customer data from social media such as Facebook, Twitter, and TripAdvisor. They also wanted to look at Wi-Fi registration data, point of sale transactions, table bookings and survey results to understand their customers.  This required a level of data integration and analysis that goes beyond just CRM alone and that’s were Customer Insights comes in. Shown below is an example of dashboard within DCI, which is tailored towards a house manager of a Marston’s inn.



Word of advice: Customer Insights for Dynamics 365 is currently in preview – available functionality is subject to change and both pricing and product naming might change before the final release. From a licensing perspective, we know see two tiers as described on the Dynamics 365 Customer Insights pricing page. Pricing is based on the amount of data which needs to be processed as well as KPIs used, predictive match policies and predictive score models.

References:




Tuesday, August 01, 2017

Introducing Cortana Intelligence Solutions

It has been a couple of months since I last looked at Cortana Intelligence Solutions (CIS) in the Cortana solution gallery so I was pleasantly surprised by a number of new solution templates which have been added.  These solution templates target different problem domains in different industries and are leveraging the full breadth of the Microsoft data platform offering – some of the scenarios covered are:
  • Predictive Maintenance for Aerospace - this Predictive Maintenance solution monitors aircraft and predicts the remaining useful life of aircraft engine components. Uses Azure HDInsight, Azure Machine Learning, Azure Event Hubs, etc … the different components are outlined in a solution diagram which is provided by the solution template as well.
  • Campaign optimization with SQL Server 2016 - demonstrates how to build and deploy a machine learning model with SQL Server 2016 with R Services to recommend actions to maximize the purchase rate of leads targeted by a campaign.
  • Vehicle telemetry analytics - this solution demonstrates how car dealerships, automobile manufacturers and insurance companies can use the capabilities of Cortana Intelligence to gain real-time and predictive insights on vehicle health and driving habits.


Cortana Intelligence Solutions is just one of the pieces in the Cortana Intelligence Suite next to Power BI, Cognitive Services, Microsoft Bot Framework and a whole lot of Azure cloud components such as Azure Machine Learning, Azure HDInsight, Azure SQL Data Warehouse, Azure Data Factory and many more.


Cortana Intelligence Suite provides both a platform and  process guidance (Team Data Science Process) to perform advanced analytics from start to finish. The main goal of Cortana Intelligence Solutions  is to reduce the complexity of deploying advanced data analytics solutions by providing Azure building blocks to operationalize your data science process. By providing these building blocks, Microsoft tries to enable companies to make smarter decisions at a rapid pace without having to worry about the complexity of designing, deploying and operating scalable data architectures.
I truly believe in the potential of data to be able to truly transform a business, a point which has been backed by the Capturing the $1.6 Trillion Data Dividend  white paper which showed that data leaders have a competitive advantages over their peers. These data leaders have a number of characteristics in common in the way that they invest in data:
  • Leverage new data such as linking transactional data with customer behavior, sensor data, social data, mobile data eetc…
  • Expanded use of analytic techniques – including more predictive analytics and big data processing techniques such as Mapreduce
  • Use new metrics – e.g. new ways of looking at operations or measuring performance
  • Include new users – expand the number and type of users who have access to the organization’s data and analytics
The interesting part of the Cortana Intelligence Suite is that it also describes the Team Data Science Process lifecycle which provides a recommended lifecycle which can be used to structure data science projects (see Data science for the rest of us for a good starting point of your new to the field of data science).



A key point that I can’t stress enough is the fact that you need a solution understanding of the business context. Data science projects are typically not IT-driven, business should be in the lead. Data science is a team effort where close cooperation with business is required to understand and identify the business problems. The most complex part of the data science process is formulating the  questions that define the business goals and that data science techniques can target. Most companies agree that managing customer churn is important, but how you define churn is different in each industry and also the impact of churn of specific customers might be different e.g in telco customers are influenced by both friends within the network and friends of friends (See Using social network analysis to predict churn which used data from a Belgian telco provider as well as the research paper Mining telecommunication networks to enhance customer lifetime predictions)

References:

Thursday, July 27, 2017

Dynamics 365 monthly reading list June 2017

Some interesting stuff was published in the last couple of weeks and due to holidays I still need to do some catching up with all the info about the Dynamics 365 July 2017 update. Enjoy

Technical topics (Configuration, customization and extensibility)

Topics for business analysts, power and end users


Previous versions of the Dynamics 365 monthly reading list:

Monday, June 19, 2017

Using Postman and the Dynamics 365 Web API (Online)

All applications performing external requests to the Dynamics 365 (online) web API first need to be registered with Microsoft Azure Active Directory to be able to authenticate using OAuth. The same also applies to Postman – for those of you who don’t know Postman, it is a pretty handy utility which allows you to perform for example REST calls without the need to write code.

For a detailed discussion about registering apps in Azure see Walkthrough: Register a Dynamics 365 app with Azure Active Directory (it still uses screenshots from the old Azure Portal https://manage.windowsazure.com but overall the steps are still valid).

To register Postman as an external application I followed these steps:
  • Select the Azure Active Directory  in which you need to register your app (Remember you can link multiple Azure Active Directories to a single Azure subscription)
  • When using Postman, you can register a native app and provide a Redirect URI - enter a value specific to your application e.g. http://localhost/postmand365app
  • Once you have registered your application, AAD will assign your application a unique client identifier (this is the ApplicationId which is listed the screenshot below. )

  • Create a secret key for your Azure app registration – make sure that you copy the key value since it will only be visible on the first save.
  • Give your application the necessary rights to connect through to CRM. Since you don’t want to show the oAuth consent screen, you want to grant the application the necessary consent. As an administrator, you can  consent to an application's delegated permissions on behalf of all the users in your tenant by clicking on the “Grant permissions” button.


If you did not correctly complete the previous steps, you will probably see some errors around invalid grants later on as shown in the next screenshot.



You have now completed all the necessary preparation  - now you need to construct the POST request to retrieve the bearer token which needs to be used in subsequent requests to Dynamics 365. You will need to do a request to https://login.microsoftonline.com/{tenantid}/oauth2/token – where tenantid is the Azure Active Directory Tenant Id.  You can retrieve this in the Azure Portal, if you click on the Help icon in the upper right and then choose 'Show Diagnostics' – this will show the the diagnostic JSON which also contains the tenantid.
  • Header:
    • Cache-control: no-cache
    • Content-type: application/x-www-form-urlencoded
  • Body
    • client_id: the ApplicationId you saw in Azure AD
    • resource: https://.crm.dynamics.com (CRM tenant url)
    • username and password:  ... 
    • grant_type: password
    • client_secret: the secret key value that you got from Azure app registration
I use Postman variables (see Using variables inside postman and collection runner) for a number of these values e.g. username, password,etc … as visible in the screenshot below. To see if everything works correctly, click on send, in the response you will see an access token that you need to use in calls to the CRM Web API.


To make this easy to use add the code snippet below to the Tests tab – this will save the access_token returned to an environment variable.
var json = JSON.parse(responseBody);
postman.setEnvironmentVariable("bearerToken", json.access_token);
To validate that this worked correctly click on the “Eye” icon in the upper right corner and you will see a “bearertoken” environment variable which can be used for subsequent requests.


To make a web request using this token using the header values below -  this will continue to work until the token expires and then you simple get a new one, by executing the request to https://login.microsoftonline.com/{tenantid}/oauth2/token and you will be able to run your requests directly within Postman.

Thursday, May 11, 2017

Save storage cost in Dynamics 365 (online) with Attachment Management solution

When files are attached/linked to Dynamics 365 records, they are stored in the CRM database which will have an impact on licensing cost depending of how much this functionality is being used. In Dynamics 365, 10 GB of storage is by default allocated to all CRM databases - for all organizations in the tenant) and 5GB is accrued per 20 full-users which are being licensed. (For more details see the Dynamics 365 Enterprise Edition Licensing guide). It is however possible to purchase additional database storage at roughly  4 EUR/GB/month. So if you accumulate 100 GB of files/documents per year – the cost might quickly rise – listed below is a rough estimate for 3 years.
Required storage Yearly cost
Year 1 100 GB € 4.800
Year 2 200 GB € 9.600
Year 3 300 GB € 14.400
There are a however a  number of options to externalize these documents/file blobs outside of the CRM databases and save money:
  • Use SharePoint Online as document storage – see Using SharePoint Online to store Dynamics CRM Online Documents for more details. This is the preferred solution if you also need to leverage SharePoint features such as document metadata, authoring/editing of Office documents, version management, etc… From a user perspective, this might however be a way of working which is not as smooth as expected.
  • Use Azure Blob storage to store your documents/files  - Azure Blob storage will roughly cost between 0.02 and 0.05 EUR/GB/month depending on reequired redundancy and type of storage (for an exact pricing  ). You will off course still need a solution to externalize these blobs. You can develop your own solution (you can use https://dynamicscrmbinarystorageoptions.codeplex.com/ as a starting point) or purchase a third party add-on such as ProStorageSaver from ProMX which will store attachments within Azure Blob Storage. Recently there is however a new solution available from Microsoft Labs on Appsource – Attachment Management
The Attachment Management solution is an add-on feature to dynamics 365 CRM Online to manage notes and email attachments using Azure blob storage. Attachment Management  not only  enables business users to optimize use of CRM Online storage but it also offers additional optional features using web resources such as multiple files upload with drag and drop support as well as  a web resources which allows to list all notes and email attachments in grid format, with download and preview of these attachment.

Figure 1. Screenshot of upload files control with drag and drop support

Figure 2. Grid view with e-mail and note attachments (including preview error)

This is a preview solution and there are still some issues:
  • Menu item for "Azure Blob Storage Settings" did not appear underneath Settings>Extensions – you can however manually add it through customization
  • Preview of documents within the grid listing does not seem to work correctly as visible in figure 2 above.
You also have to keep in mind that if you already have some existing attachments in Dynamics 365 (online), you will have to write some code to move them to Azure blob storage in the same way as the current solution does since this is not supported in the current version.






Monday, May 01, 2017

Dynamics 365 monthly reading list 01/05/2017

Lots of interesting news on Dynamics 365 the last couple of weeks – keep up to date by subscribing to this blog.
Technical topics (Configuration, customization and extensibility)
Topics for business analysts and power users

Monday, April 24, 2017

The Dynamics CRM consultant tool belt

To be truly productive as a Dynamics CRM consultant you need a good toolkit to automate tedious or labor-intensive tasks. While you can solve anything by writing code – it just gets a lot easier when you can leverage the tools built by the CRM community. Listed below are the tools which I have used in the last 12 months – leave a comment if you think I have missed an essential utility in your tool belt.

  • Ribbon workbench for Dynamics CRM  - the standard for editing the Dynamics CRM Ribbon since CRM2011, it can now also be installed as a plugin for XRMToolbox
  • XrmToolBox – the Swiss army knife for CRM consultants, it is a windows application on which 30+ plugins can be added to automate a number of tasks – listed below are some of the XrmToolBox plugins I have recently used
    • Metadata Document Generator: a tool to generate Excel and Word documents with entities and attributes information - also take a look at  Spring Cleaning for your Dynamics CRM system about how you can use it to clean up your CRM system
    • Script Finder: lists all client events defined in an organization
    • Solution History for CRM 2013/2015/2016: allows you to view a historical list of solutions that have been imported, as well as display how many times a solution has been imported, version number that was updated and error/warning messages that were encountered during solution import
    • FetchXML Builder: Build and test FetchXML with all capabilities supported by the CRM platform, etc …
  • CRM Diagnostics Toolkit
  • Trace reader for Dynamics CRM (Codeplex)  
  • Level Up for Dynamics CRM (Chrome extension) 
  • Random test data generator 
  • Dynamics CRM/365 Developer Extensions - is a very worthy replacement of the SDK Developer Toolkit. It contains a lot of templates and will accelerate your development of plugins and workflows
  • CRM Rest Builder – a tool to generate Javascript code using the 2011 & Web API REST endpoints
  • XRM CI Framework - provides you with the tools automate the build and deployment of your CRM solutions. Use the framework to implement a fully automated DevOps pipeline, which will allow you to deploy more frequently with greater consistency and quality.
  • Fake XRM Easy – unit test library for Dynamics CRM/365 plugins and workflows
  • ConfigDataMover – Tool used for synchronizing data in different CRM environments (from @lucas_is)
  • Dynamics 365 workflow tools – this solution contains 30+ workflow activities which will help you to be more productive when designing Dynamics 365 process (from @demian_rasko )

Also check out these other tool lists – Your essential toolkit for Dynamics CRM (from @jukkan)

Thursday, April 20, 2017

Getting a head start developing Dynamics CRM plug-ins

In this article I will explain what Dynamics CRM plug-ins are and which tools you can use to speed up the development of CRM plug-ins. The goal of this article is not to explain the logic behind plug-ins in detail, you can look a the links outlined in the references section of this blog post for that. I will however provide you with the most important information to get you started building your first Dynamics CRM plug-in with Visual Studio 2015 using the different tools : Microsoft Dynamics CRM SDK Templates, Microsoft Dynamics 365 Developer Toolkit, Dynamics CRM & 365 Developer Extensions or JonasPluginBase

A plug-in is an event handler (packaged as a .NET assembly) that can be used to intercept events generated from the  Dynamics CRM system, to perform a number of actions in code.  Apparently the underlying architecture of plug-ins has not changed a lot since Dynamics CRM 2011 so developers who have building these for previous versions can still use the same code base. So in essence plug-ins are .NET classes that implement the Microsoft.Xrm.Sdk.iPlugin interface. One or more plug-in classes can be contained in a .NET assembly (class library) – so you can just create a new class library project, add a reference to the Microsoft.Xrm.Sdk.dll (part of the SDK), add a class which inherits from Microsoft.Xrm.Sdk.iPlugin and implement the Execute method. You will also need to add to sign your assembly with a strong name.

But to let CRM know that your code needs to run, you will need to register your assembly to be invoked as part of the message execution pipeline that occurs when a CRM message is being processed. So first you will need to define on which type of message you want to react (e.g. associate tasks upon creation of a new account, setting default values, etc …) – these can be common messages such as create, retrieve (read), update or delete but also specific messages such as AddToQueue. Most message types are available for extension but there are some exceptions – check out Supported messages and entities for plug-ins.

Another design decision that you have to make when registering your plug-in, is whether it needs to run synchronously or asynchronously. Do realize that the choice between synchronous or asynchronous is also defining at which stage you can register your plugin e.g. an asynchronous plugin will only run post-operation and is not part of the database transaction (See Event execution pipeline for more details about the different stages).


The third design decision you will have to make, is deciding where your code will execute – Dynamics CRM provides two different options:
  • Full-trust (or non-isolated): synchronous plugins will run within the W3WP.exe process of IIS, and asynchronous plug-ins in the AsyncService which host the process. This is only possible in on-premise deployment and although slightly faster you will loose the benefits of …
  • Sandbox execution (or isolated mode): executes in the Microsoft.Crm.Sandbox.Workerprocess.exe process This should be your default choice unless you have a good reason not to use sandbox execution. This is the only option for CRM Online deployment but also has some limitations such as a two minute execution limit but also provides some benefits such as collection of run-time statistics about plugins-ins and custom workflow activities that run in the sandbox.  – I recommend that you read Plug-in isolation, trusts and statistics for more information as well as Understanding plugin sandbox mode.
To actually built the logic for your plugin you will need to use iPluginExecutionContext which provides information about the execution of the plugin such as (See Understand the data context passed to a plug-in for more information)
  • MessageName: name of the message in this case Create
  • Stage: stage that a plugin is being invoked e.g. 20 for Pre-Operation
  • PrimaryEntityName: name of the entity that triggered this message e.g. “lead”
  • InputParameters: Parameters from the request message – e.g. for a createrequest there is parameter of type “target” which contain
  • OutputParameters: Response message after the operation has completed
The next code sample shows how you use the PluginExecutionContext and how you leverage interfaces such as iTracingService (Provides a method of logging run-time trace information for plug-ins) and iOrganizationServiceFactory which allows you to create an instance of the organization service.

Option 1 : Dynamics CRM SDK Templates
As you noticed there is a quite a lot of plumbing code needed before you can get started. Fortunately there are alternative ways to start coding your CRM plugins such as the Microsoft Dynamics CRM SDK Templates (also part of the Dynamics CRM 2016 SDK). This provides a Visual Studio project template with a pluginbase class so that a lot of the repetitive plumbing code can be eliminated.



Option 2: Microsoft Dynamics 365 Developer Toolkit
Recently Microsoft also released an updated version of their CRM developer toolkit – Microsoft Dynamics 365 Developer Toolkit which is a set of Microsoft Visual Studio integration tools, focused on accelerating the development process. I recommend that you read Microsoft Dynamics 365 Developer Toolkit Series – Part 3  to get a feeling how you can use the Dynamics 365 Developer Toolkit.

Option 3: Dynamics CRM & 365 Developer Extensions
There are however also other tools out there such as the Dynamics CRM & 365 Developer Extensions from Jason Lattimer which is a very worthy replacement of the SDK Developer Toolkit. It contains a lot of templates and will accelerate your development of plugins and workflows by allowing for a one-click deploy directly from within Visual Studio but also contains building blocks for using unit test for your plug-ins. It currently supports Visual Studio 2012, 2013 and 2015.


Before you can use the CRM Developer Extensions you will need to change some settings in Visual Studio 2015 – go to Tools>Options and navigate to CRM Developer Extensions (See screenshot below)



Option 4: Microsoft Dynamics CRM/365 Plugin base class
Jonas Rapp also has a very light-weight and simple to use plugin-base class available which also includes tracing and timing information – check out https://github.com/rappen/JonasPluginBase

References:

Thursday, April 06, 2017

Dynamics 365 monthly reading list 06/04/2017