Showing posts with label #msdyncrm. Show all posts
Showing posts with label #msdyncrm. Show all posts

August 11, 2018

Display a Two Options field as checkbox inside a Quick View Form

The other day I was working on a project involving a Quick View Form, nothing complicated but in the end it required some additional steps to achieve the desired result.
The purpose of this Quick View Form (for the Account entity) was to show a single Two Options field, so the users don't need to open the related account record to see the value of this boolean field.
As usual I created the Quick View Form, added the Two Options Field, save & publish, added the Quick View Form inside the other entity, save & publish. All was working except the Two Options Field was displaying as a label showing Yes or No:



As I need to show this field as a checkbox, first thing I thought was: "no big deal, I back to the form editor and I change the formatting to show a checkbox", the only problem is that the "Formatting" tab inside the field properties is missing when you work with a Quick View Form:



So it is not possible to set the Control Formatting style to display the field as a checkbox, as you can do inside a standard or a Quick Create Form:



A workaround is to manually edit the solution XML and change the classid attribute of the control to a specific value.

Beware: you should do this kind of editing only if you know what you are doing, I don't encourage to go and edit files without having a proper knowledge of the XML structure.

First step I did is to create a new solution containing just the Quick View Form I needed to edit, this is possible with the "Select Entity Assets" wizard of the latest versions of Dynamics, if you are on an older version you need to add the entire entity (with all the forms, views and fields) to the new solution.



After I exported the solution as Unmanaged, I extracted the zip file to a folder and I edited the file customizations.xml. In order to find the right place to edit I searched for the logical name of the field (in my case marketingonly) and I was in front of the definition:
<cell id="{32660749-eb65-6c8d-208c-664929db91db}" showlabel="true" locklevel="0">
  <labels>
    <label description="Marketing Only" languagecode="1033" />
  </labels>
  <control id="marketingonly" classid="{67FAC785-CD58-4F9F-ABB3-4B7DDC6ED5ED}" datafieldname="marketingonly" disabled="false" uniqueid="{b751c953-ac42-7723-a3c5-d4c7b0514c0b}" />
</cell>
As I mentioned before the attribute to update is classid, so I changed the guid value to {B0C6723A-8503-4FD7-BB28-C8A06AC933C2}, if someone is curious where this specific value comes from, it is listed inside the FormXml definition as the value for CheckBoxControl, or you can export another form with a checkbox and you will find the same guid value.

Done with the edit I saved the file, zipped the solution files, imported and published, and finally the Quick View Form now shows a checkbox:



Hope it helps!

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)
{
  try
  {
    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);
  }
}

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!