July 15, 2018

Say No to local Option sets (but pay attention in PowerApps)

The use of global option sets in Dynamics is normally considered a best practice, the obvious advantage is the ability to reuse the same list of options in multiple fields inside the same entity or a different one.
Dynamics still allows the creation of local option sets but from version v9 there is another difference between Local and Global option sets: the External Value property:

This property is available only on Global option sets, when you create a local option this new property is missing:

External Value is intended for Virtual Entities, I understand it's not an everyday situation to deal with it, but this gives you another reason to avoid local option sets.

Today we live in the world of CDS and PowerApps, but the choice between local and global option sets is also inside the Canvas mode. If before the creation of fields was handled generally by System Administrators (in what we call today model-driven apps), today a larger set of user can face this dilemma.
Microsoft published a detailed page regarding option sets inside PowerApps here:
Create an Option set
So make your users aware of the "Option sets" inside the navigation pane:
Although I agree with the warning written by Microsoft

"Local option sets can only be used by the entity and field they are created against, and cannot be reused on other entities. This approach is only recommended for advanced users that a specific need for a local option set."

teach your users that the options inside a global option set will be available in all the fields using that option set, so if you add or remove options this will affect also other fields created by different users based on the existing option set.

January 27, 2018

365 Saturday London: recap of the Community Event

As I anticipated in my previous post, this weekend I attended the 365 Saturday event in London (http://365saturday.com/dynamics/london-jan2018/), if I need to describe the event in one word? EPIC.

This 365 Saturday was a 2 days event, the first part on Friday afternoon with the Hackathon and the second part on Saturday with many sessions (there were 5 tracks!) from early morning until 6pm, practically a full day of Dynamics 365 content.

The Friday Hackahton was divided in two tracks, the first one regarding Field Service by @BenVollmer from Microsoft the second track was focused on various aspects of Dynamics 365: Machine Learning, Microsoft Portals, Xamarin and XrmToolBox, the must-have tool for Dynamics professionals. Personally I followed the Field Service part of the Hackathon and during the breaks I snooped into the other track :)

The Hackthon was very interesting but Saturday has been off the charts. The day started with the keynote of James Phillips, Microsoft Vice President in charge of the Dynamics products and he dropped the big news of the day: Microsoft decided to revert the deprecation of the the Outlook Client, I will not go into the details as I am sure in the next days there will be detailed blog posts regarding this important announcement.

As I don't have the gift of ubiquity (yet) I was able to attend only few sessions, I started with the one by Ramón Tébar Bueno and Baris Kanlica regarding Dynamics 365 v9 I did a speech at CRM Saturday Milan back in November about the same argument, but this session confirmed me one thing: Dynamics 365 v9 is full of new features and is difficult to concentrate all of them inside 1 hour.

The second session I followed was the "GDPR Considerations" by Mohamed Mostafa GDPR is a delicate argument and the deadline (25 May 2018) is near the corner, we (Dynamics professionals) should focus more on this topic and Mohamed session was very helpful to understand some of the key points of the regulation.

The next session was "Resource Scheduling Optimization" by Ben Vollmer, a different session was scheduled for this slot but the speaker was not able to attend, so Ben kindly step in and delivered this unexpected session regarding Field Service RSO. Resource Scheduling Optimization is a very interesting tool and I'm glad that I learned something about it.

The last session was about PowerApps, Flow and PowerBI, delivered by Darshan Desai and Rory Neary The first part Darshan talked about PowerApps and Flow and the second part was delivered by Rory where he presented an interactive PowerBI dashboard embedding a PowerApps app designed for James Bond (the event was in UK, logical choice), the session was the right mix between technical content and entertainment.

Last but not least, the 365 Saturday supports women in tech, Janet Robb who works for Microsoft and helped in the organization of the event is our advocate for this important cause: I'm very happy that I joined the first 365 Saturday of 2018, I met old friends, made new ones and meanwhile I learned something new about Dynamics 365, it's amazing. Last thing: don't forget to check their website (http://365saturday.com/) for the upcoming events!

January 22, 2018

365 Saturday in London and what I have been up to

This weekend (26 and 27 January) I will be in London to attend the 365 Saturday event (http://365saturday.com/dynamics/london-jan2018/).
I'm sure that 365 Saturday will be a big event, not only because is the first one with the new brand (it was previously known as CRM Saturday) but the speaker lineup is impressive: in addition to several MVPs that will go deep-dive into various subjects, James Phillips (Microsoft Corporate Vice President) will be the keynote speaker and Ben Vollmer (Microsoft Global Field Service Lead) will host a workshop regarding Field Service.

Registrations are now closed for the London event, but check their website (365saturday.com/) to find the next events, like the one in Amsterdam next month or the one in Dallas in March (first time in the USA).

And now just a quick update on what I did in the last months regarding Dynamics CRM/365:
  • 25 November 2017 I was one of the speakers for CRM Saturday in Milan, big thanks to Stefano Tempesta for organizing the event. I did a session on the new and deprecated features of Dynamics 365 v9, I had a great discussion with the participants and soon it's UPGRADE TIME!
  • Still in November I was invited to the CRM Audio podcast (episode here) for a little chat regarding Dynamics. CRM Audio hosts several podcasts like the one about PowerBI or the "Implement This" series, check it out.
  • Dependent OptionSet Generator: After the V9 release I decided to update my solution for dependent optionsets (download here). The big news is the support for the Multi Select OptionSets. The demo has also been updated for this release.
  • Dynamics Weekly (www.dynamicsweekly.com): Back in December I decided to start a newsletter regarding Dynamics, the idea is to organize fresh content (articles, tools, videos, podcasts released in the previous week) delivered directly to your inbox. This morning I sent the 8th issue and there are nearly 200 subscribers.
Posted on Monday, January 22, 2018 | Categories:

November 9, 2017

Catch the Revise Quote message inside a Plugin

A user in Dynamics CRM/365 can revise a Quote, it's a process where the old quote is closed and a new quote is created in draft state and ready to be updated.
Dynamics doesn't support a specific message that we can intercept (in order to register a plugin step) when a quote is revised, however one of the possible ways is to deal with the Create message.

When quote are revised the integer (Whole Number) field revisionnumber is increased, this field is managed by the platform as it is not valid for Create or for Update according to its Metadata.
So when a new quote is created the revision number is 0, and the revised quotes will have 1,2,3...
Fetching the quote with the previous revision number is not a clever method to retrieve the revised quote. For example if we have an original quote (0) in Closed state and a revised quote (1) in Closed state too (because we cancelled), we are able to revise the original quote (0) and the new quote will have 2 as revision number.

My friend Daryl LaBar (@ddlabar) suggested to check the ParentContext property inside the plugin in order to access to the ReviseQuote message that initialized the create message.
In the end I wrote a plugin (registered on the Create message, Pre-Operation, Synchronous) to check the Parent Context and get the reference of the revised quote. Here the code:
public void Execute(IServiceProvider serviceProvider)
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
      Entity currentQuote = (Entity)context.InputParameters["Target"];
      if (currentQuote.LogicalName != "quote") { return; }
      // check the revision number first
      int revisionNumber = currentQuote.GetAttributeValue<int>("revisionnumber");
      if (revisionNumber > 0)
        IPluginExecutionContext parentContext = context.ParentContext;
        // check if the Parent Context contains the QuoteId parameter of the ReviseQuote message
        if (parentContext.InputParameters.Contains("QuoteId") && parentContext.InputParameters["QuoteId"] is Guid)
          Guid revisedQuoteId = (Guid)parentContext.InputParameters["QuoteId"];
          IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
          IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

          Entity revisedQuote = service.Retrieve("quote", revisedQuoteId, new ColumnSet(true));
          // rest of the code

  catch (Exception ex)
    throw new InvalidPluginExecutionException(ex.Message);

September 21, 2017

Microsoft Portals Source Code Teardown - Episode 1 - The Solution

If you are reading this post you probably know that Microsoft released the source code of the Microsoft Portals (former ADX Studio) under the MIT license.

I have a fair experience with the code of ADX Studio 7.x but this release include also the source code of some DLLs, so I thought that analyzing parts of the source code can be interesting for Dynamics developers.

Download link: Microsoft Dynamics 365 Customer Engagement Portals Source Code
The file of interest is MicrosoftDynamics365PortalsSource.exe, after extracted the main Visual Studio solution (Portals.sln) is under the folder Solution\Portals\

In this post I will focus on the project in general, in the next episodes I will examine specific pieces of the source code that I find interesting.

The main project is MasterPortal, it is an ASP.NET MVC website configured to run with .NET Framework 4.5.2 and basically is the upgrade of what we got with the previous ADX Studio Portals.
The second project is Framework, this is the source code of the ADX Studio DLLs, like Adxstudio.Xrm.dll and the now "obsolete" Microsoft.Xrm.Client.dll, inside this project the first surprise, a project called SafeHtml, from a quick look (and as the name suggests) the purpose is to sanitize html inputs, a good candidate for a future post.

Now let's check the nuget packages, beside the standard packages used by ASP.NET MVC, the Portals solution also references these packages (this is not a complete list, only the ones that got my first attention)
  • Bond.CSharp - Bond is an open source, cross-platform framework for working with schematized data. It supports cross-language serialization/deserialization and powerful generic mechanisms for efficiently manipulating data. - I will check where this "framework" is used inside the portal
  • Lucene.net - Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users. - I worked with Lucene.net some years ago for one university exam, is a very powerful library
  • DotLiquid - DotLiquid is a templating system ported to the .NET framework from Ruby’s Liquid Markup. - So this is the library used by the Portals to handle the liquid templates
the first sneak peek inside the Portals source code ends here, see you soon!

May 24, 2017

Xrm.Page.context.getVersion is now a supported method, use it!

Recently the MSDN page regarding the Client-side context methods of Dynamics 2016/365 has been updated and thanks to the Dynamics team a new method is inside the documentation: Xrm.Page.context.getVersion.

Some developers are already using this method in their code, personally I didn't because I had not the necessity to differentiate between the 8.x endpoints.

The method returns a string containing the full version in the Major.Minor.Build.Revision format, an example is "".

In the previous CRM versions if we want to get the version from the client we had two ways:
  • call the RetrieveVersionRequest message using the SOAP endpoint (example)
  • check if a specific CRM function exists (example)
I used often the second way because I always considered doing a server call (often synchronous) not a good choice for the script performance.

Why we want to know the current CRM version? Because some functions are available only from a specific version, like the one to execute a workflow: the Microsoft.Dynamics.CRM.ExecuteWorkflow introduced with the 8.2 release.

But for the Web API endpoint we need to provide only Major.Minor and not the full version, therefore a transformation is necessary.

The following code maybe will be considered exaggerated by someone but creating a robust piece of code will reduce the necessity to change the script in the future:
function getCurrentVersion(context) {
    if (context.getVersion == undefined) { return ""; }
    var versionArray = context.getVersion().split(".");
    if (versionArray.length < 2) { return ""; }
    return versionArray[0] + "." + versionArray[1]; 
The result from the "" is "8.2" ready to be inserted inside your Web API url.

Few considerations:
  • If the version cannot be retrieved I decided to return an empty string, but you can return null, throw an exception, call another method, set a default value, etc etc...
  • the function requires the context, in this way you can use in the form scripts (like an onload event) or inside a WebResource
  • I decided to split the string to an array using the dot (.) I think this is the most robust way compared to doing a substring or expecting a second dot in the string

May 15, 2017

CRM Saturday Zurich: recap of the Community Event

Last weekend I attended #CRMSaturday in Zurich, for those not familiar with the name, CRM Saturday is a series of events across Europe (but they are going global with the July event in Australia) focusing on Dynamics 365 for Customer Engagement (or Dynamics CRM if you prefer).

Conferences and events like this are an important part of the CRM ecosystem, when you work on a platform like Dynamics 365 that implements new features rapidly, a community event can be a perfect opportunity to keep yourself up to date learning something new or go deeper with a specific functionality.

The location for the Zurich chapter was the Microsoft Offices in Switzerland, a perfect venue considering that this was a joint event with SharePoint Saturday Events, the available tracks in totally were three (2 for SharePoint and 1 for CRM).

Stefano Tempesta, one of the organizers of CRM Saturday, gave an introduction before the keynote of Kathrine Hammervold from Microsoft Norway.
The CRM track started with the session of Baris Kanlica titled "Dynamics 365 new features and deprecations", with the upcoming release this is an hot topic and personally I learned about the use of control notifications (Xrm.Page.getControl(arg).setNotification(message,uniqueId)) The next speaker was Razwan Choudry with his session about Solution Management. How to manage solutions, how to implement versioning and the infamous "Add all assets" checkbox were some of the topics covered. The message was to put more attention on the maintenance and the deployment of a solution, and I couldn’t agree more. After the lunch break was the turn of Marius Agur Pedersen with his session about Azure. He focused on Azure Service Bus and Azure Key Vault, we can bet that Azure and Dynamics 365 will be more integrated in the future. I am often inclined to don't use Azure Service Bus, but with Marius reassurances about the bus performance I will try it again. The following session was with Jordi Montaña and his testing framework Fake Xrm Easy. Unit testing is a must for medium and big projects, but should be also a priority for smaller projects that contains only a couple of plugins. The framework he created is impressive, I know how broad and different are the CRM messages and the IOrganizationService and to mock all that stuff requires countless hours. Next to the stage was Christoph Mäder with his session to improve the performance of a Dynamics CRM/365 OnPremise instance. Many customers still prefer to have their CRM in house or they are not ready to move to the Cloud, but this doesn't mean that they can't tune their instance or take advantage of some possibilities offered by an OnPremise installation. The last one to speak was Mohamed Mostafa with the other side of the medal: Considerations for Cloud Dynamics 365 Deployments. His session went through the major aspects of an Online implementation, the compromises and the big advantages to have Microsoft taking care of your instance, considering also the upcoming EU GDPR (General Data Protection Regulation). It was an amazing event and experience for me, I had the chance to met in person people that I know virtually from a long time. Despite some tweets that list me as speaker, I only attended and I was not involved in the organization of the event, all the credits goes to the other guys in the next picture, they used their time and energy to make this happen, I'm honored to know them and they are an inspiration for the community. CRM Saturday was free, so a "thank you" should be made also to the sponsors. Bottom line: attend the next CRM Saturday!