Dynamics CRM 2015 – Customizing Hierarchies

Microsoft Dynamics CRM now provides you with a hierarchical view of records out of the box for selected entities, with the ability to customize this view for custom relationships. It is also possible to customize the hierarchy tile view to display different fields on each tile.

Firstly, let’s see how the out of the box Account to Sub-Account relationship is configured to display a hierarchical view. If we go into our customizations area and take a look at the 1:N relationship self-referential relationship for Accounts, we will see a new Hierarchical option which is set to “Yes”. Note that this cannot be changed.

clip_image002

Looking at the Account to Contact 1:N relationship, we will see that this option is set to “No” and again cannot be changed. This means we cannot view Contacts belonging to a particular Account from within a hierarchical view. The 1:N self-referential relationship for Contacts is also not enabled for hierarchies.

clip_image004

Can I enable Hierarchies for Custom Relationships?

You sure can! Here I have created a custom 1:N self-referential relationship for Contacts and have set Hierarchical to “Yes”.

clip_image006

Next, we need to create a new Hierarchy Setting under the Contact entity. This is done under the entity configuration and is solution-aware which means the rules are included when you deploy the solution to another environment.

clip_image008

Clicking on New brings up the configuration settings for a new Hierarchy. Enter a unique Name and select a Default Quick View Form which will be used when displaying the tiles for each record in the hierarchy. I have decided to use the Contact Quick Form but you can also choose to create a new Quick View Form if you wish.

clip_image010

To obtain a list of relationships for the current entity which are enabled for hierarchies, click on the hyperlink. You can select a relationship in the list and mark it as hierarchical.

clip_image012

Click on Save and Close and then publish all customizations. After linking Contacts together via my new custom relationship, I can now see that these records are part of a hierarchy and I can simply click on the hierarchy button to view the hierarchy.

clip_image014

clip_image015

Notice how we have four fields on the hierarchy tile. The default Contact Quick Form also includes the Company Name field, but this is not displayed on the tile. It appears that only a maximum of four fields can be displayed. I have added the Home Phone field before the Mobile Phone to illustrate my point.

clip_image017

clip_image018

Notice how the Mobile Phone field is no longer displayed.

There you have it! A very simple way to configure entity relationships to take advantage of the new hierarchy feature in Dynamics CRM. Remember that the hierarchy feature is available for the Account, Campaign, Case, Contact, Opportunity, Order, Product, Quote, Team and User entities.

Dynamics CRM 2015 – Hierarchies

This feature has been requested over and over and I can gladly say it is finally available out of the box! Yes, I’m talking about the ability to view a hierarchy of records in a tree view from within your CRM system. This feature is available for the Account, Campaign, Case, Contact, Opportunity, Order, Product, Quote, Team, and User entities, but is only enabled out of the box for the Account, Product and User entities.

clip_image002

Firstly, let’s take a look at how this work for Accounts. I have setup four Accounts in CRM where none of the Accounts are related to one another. The screenshot below shows what this looks like in the “Active Accounts” view – nothing special here.

clip_image003

It would make more sense if the “Magnetism” account was the top-level entity, with each of the other accounts sitting beneath it as sub-accounts. We can achieve this by setting the Parent Account field on each of these records.

clip_image005

After saving these accounts, you will notice a new button is displayed next to the “Previous” and “Next” record buttons on the form. This button tells the user that this particular account has a hierarchical relationship with other accounts.

clip_image007

Clicking on this button displays a hierarchical view of related accounts where the one highlighted in orange represents the record that you were currently working on.

clip_image008

Each record is displayed on a separate tile and the user can select a different tile to open the record. To the left of the hierarchical view, we have a navigation control. Clicking on a specific link on this control highlights the associated item in the hierarchical view.

clip_image009

clip_image011

If we go back to the “Active Accounts” view, we will see that the button is available next to each related account to view the hierarchy of accounts.

clip_image012

As mentioned above, the hierarchical view is available for a number of entities, including the User entity. Selecting a particular tile in the tree only displays the direct children of that record and an overflow button is available to click to view records further down the tree.

clip_image014

The hierarchical view is customizable for out of the box and custom entities and the information shown on the tiles can also be modified. We will take a look at these customization features in my next post.

Fix Incorrectly Created Status Reasons in Dynamics CRM

The Status Reason field in Dynamics CRM is a special field which allows you to provide reasons for the status of a particular record. For example, an Article can have a Status of “Active” and a Status Reason of “Awaiting Review”, “Approved”, “Published” etc. Likewise, an Article can have a Status of “Inactive” and a Status Reason of “Expired” or “Deleted”. But what happens if you configure your Status Reasons incorrectly?

I had recently made a mistake while configuring the Status Reason field such that a user could set an Article to Active – Deleted, which was not the desired functionality. The “Deleted” status reason should instead be linked to the “Inactive” state.

clip_image001

The CRM implementation also enforced strict rules so that the “Deleted” status reason must have an ordinal value of 213,940,003. Let’s see what happens when I try to simply re-create the “Deleted” status reason against the “Inactive” state.

If I try to delete and re-create the “Deleted” status reason, the CRM platform automatically assigns it the next available ordinal value of 213,940,006 and it appears that I cannot change this value.

clip_image002

Thankfully there is a way to change this value without any nasty database hacks.

Firstly, remove the “Deleted” status reason, save your changes and publish customizations. Next, add the “Deleted” status reason to the list of “Inactive” status’ as we previously attempted.

clip_image004

On the Add List Value screen, press F12 to launch Internet Explorer Developer tools.

clip_image002[1]

Make sure the HTML tab is selected and then select the cursor icon.

clip_image005

Back on the Add List Value screen, hover over the Value textbox so it appears with a blue outline and then click the mouse.

clip_image006

Back on the Internet Explorer Developer Tools screen, on the right-hand pane, select Attributes and then select the disabled attribute. Press the delete button to remove this attribute.

clip_image008

The Value field will now be editable. Change the value from 213,940,006 to 213,940,003 and then click on OK.

clip_image009

Save the changes to the Status Reason field and publish customisations. The “Deleted” status reason will now be available to select when making records inactive.

Quick Tip: Generate GUIDs in Visual Studio 2013

Here’s something helpful. If you want to generate a random GUID (perhaps for unit testing), you can easily do this from the Visual Studio 2013 tools menu. Click on Tools –> Create GUID to open up the “Create GUID” options window.

clip_image001

clip_image002

There are many different GUID formats so choose the one that suits you. I selected option 4 which generates a basic GUID inside curly braces. Click on the Copy button and you’re away laughing!

The Grid Layout in Bootstrap

One of the great things about Bootstrap is that it simplifies the task of creating grid layouts in your web applications. Developers with basic knowledge of front-end web development hate fiddling around with CSS to position content into rows and columns and can greatly benefit with Bootstrap’s ability to control how they appear on different screen resolutions.

The one rule of Bootstrap grids is that each row can have a maximum of 12 columns. There are a number of predefined CSS classes that help you specify the number of columns in a specific row and how much horizontal space each column occupies. Let’s take a look at some examples:

Example 1: Row with Two Columns (50/50 Split)

The code snippet below shows how we can create a row with two columns of equal width. I have defined a <div> tag with a class of “row” which contains two <div> tags that each have a class of “col-md-6”. Remember that each row can have a maximum of 12 columns, so we are specifying that each column takes up 6 units.

<div class="row">
    <div class="col-md-6">
        <h1>LEFT</h1>

        <p>
            This content appears on the left side
        </p>
    </div>
    <div class="col-md-6">
        <h1>RIGHT</h1>

        <p>
            This content appears on the right side
        </p>
    </div>
</div>

The “md” applies this CSS style to medium-sized screens (maximum width 992px). If we drop the window size so that it is less than 992px, the divs will no longer be side-by-side, and instead will be stacked on top of one another.

If we want to keep the 50/50 split on all sized screens, we can use the class “col-xs-6” where the “xs” stands for “extra-small”. Other options include “sm” (small) or “lg” (large).

clip_image002

clip_image004

If we wanted to have three columns of equal width within our row, we can simply use a class of “col-md-4”.

Example 2: Row with Three Columns (One Large and Two Small)

Here’s an example of how we can take the code snippet above and easily modify it to include three columns where the left-most column takes up half the screen.

<div class="row">
    <div class="col-md-6">
        <h1>LEFT</h1>

        <p>
            This content appears on the left side
        </p>
    </div>
    <div class="col-md-3">
        <h1>MIDDLE</h1>

        <p>
            This content appears in the middle
        </p>
    </div>
    <div class="col-md-3">
        <h1>RIGHT</h1>

        <p>
            This content appears on the right side
        </p>
    </div>
</div>

The screenshot below shows what this markup would output on a medium-sized screen.

clip_image002[4]

Again, if we drop the window size, the columns are stacked evenly on top of one another.

clip_image004[4]

Example 3: Grid Layouts on Mobile Browsers

I mentioned above that we can prevent the columns from stacking top to bottom by using the “col-xs-…” class. This is useful if we want to maintain column layout on smaller devices such as tablets or smartphones. Here is the same code snippet from example one with “xs” used in place of “md” on a very small window size that would be fit for a smartphone.

clip_image005

That’s all there is to it! There are some variations that you can add to the row/column layout to make your web applications more interactive. We will take a look at these in my next few blog posts.

Add Bootstrap to your MVC Applications

Bootstrap is a free CSS library that makes it very easy to create layouts and apply styles to your web application. The library provides many pre-defined CSS classes which let you create rich and interactive user interfaces to simple HTML elements such as divs, tables and unordered lists. Please note that this blog post refers to Boostrap in the context of an ASP.NET MVC application.

Bootstrap is automatically included when you create a new ASP.NET MVC Web Application in Visual Studio, provided that you don’t’ select the Empty template. However, in this example I will select the Empty template and see how we can include the Bootstrap dependencies via NuGet.

clip_image002

My Solution Explorer shows a completely empty web project.

clip_image003

I can simply right-click on the project, click on Manage NuGet Packages and search for “Bootstrap”.

clip_image005

Click on Install. This will add a new Content and Scripts folder to your web application. You will also notice that JQuery libraries are also included in the application.

clip_image006

Now that you have Bootstrap and it’s dependencies installed, you can reference them in your MVC Views (or HTML files) and start building rich user interfaces.

How to generate a random password with .NET

I have been working with ASP.NET MVC4 and needed the ability to generate a random password for a personal website I have been building. The System.Web.Security namespace makes it very easy to accomplish this through one line of code.

string randomPassword = Membership.GeneratePassword(8, 2);

The GeneratePassword method takes in two parameters. The first is the length of the password you wish to generate and the second is the number of non-alphanumeric characters to include in the password. Here is an example of some randomly generated passwords using this method.

cWkX-2+G
*}MPeRZy
cV&^f$-C

Enjoy!