Microsoft Dynamics CRM 2011 – Hierarchical Treeview – Version 0.1

 

Rémi Boigey, Partner Technical Consultant @ Microsoft France, did a great Silverlight application (version 0.1) for  Microsoft Dynamics CRM 2011 that we share you today.

Solution Features

  • Dynamically display associated entities with the current record.
  • You can customize the display.
  • You can open records from the list

image

Next Features

  • Create a user interface in order to customize the view without coding.

Installation

Step 1 : Save the CRM solution on your disk -  SilverlightHierarchicalRelatedEntity_1_0_0_0_managed.zip

Step 2 : Import the solution – Settings / Solutions / Import

importsolutionCRM2011

Click on Browse Button and select the solution SilverlightHierarchicalRelatedEntity_1_0_0_0_managed.zip.

Click on next buttons and close the form.

Test the solution

In order to test the solution, We provide you a pre-configuration file for an account inside the solution.

In Settings/Customization/Customizations/Customize the System, select the account entity and edit the main Form.

Edit or add a new section.

Click on Insert tab, and then select Web resource 'Hierarchical Related Entity (Account sample).html'

WebRessources1CRM2011

WebRessourcesCRM2011

WebRessources2CRM2011

Save and publish the account form.

Customization

You can reuse and customize this solution for different entities, to do this follow the following steps :

  • Create a new HTML web resource (either in the default solution or in a custom solution)
  • Copy and paste the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="https://www.w3.org/1999/xhtml" > <head> <title>Sample hierarchical Related Entity</title> <style type="text/css"> html, body { height: 100%; overflow: auto;     }

body {              padding: 0;              margin: 0;     }     #silverlightControlHost {              height: 100%;              text-align:center;     }

    </style>     <script type="text/javascript" src="gps_scripts/Silverlight.js"></script>     <script type="text/javascript" src="gps_scripts/hierarchicalrelatedentity.js"></script>     <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>     <script type="text/javascript">

        var slConf = '<?xml version="1.0"?>' +

                        '<hierarchies xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema">' +

                            '<hierarchy entity="account" pk="accountid" icon="gps_imgs/ico_account.png" displayField="name"  UrlBody="/main.aspx?etc=1" UrlBodyExtra="extraqs=id=" UrlSuffix="pagetype=entityrecord">' +

                                '<relatedEntity  name="activitypointer" pluralName="Activités" pk="activityid" fk="regardingobjectid" displayField="subject|string,ownerid|EntityReference,scheduledstart|System.DateTime,scheduledend|System.DateTime" icon="gps_imgs/ico_activity.png" UrlBody="userdefined/edit.aspx?etc=4212" UrlBodyExtra="id=" UrlSuffix=""  />' +

                                '<relatedEntity  name="opportunity" pluralName="Opportunités" pk="opportunityid" fk="customerid" displayField= "name|string,estimatedvalue|Money,estimatedclosedate|System.DateTime,closeprobability|int,ownerid|EntityReference" icon="gps_imgs/ico_opportunity.png"  UrlBody="main.aspx?etn=opportunity" UrlBodyExtra="extraqs=id=" UrlSuffix="pagetype=entityrecord"  />' +

                                '<relatedEntity name="contact" pluralName="Contacts" pk="contactid" fk="parentcustomerid" displayField="fullname" icon="gps_imgs/ico_contact.png"   UrlBody="main.aspx?etn=contact" UrlBodyExtra="extraqs=id=" UrlSuffix="pagetype=entityrecord" />' +

                                '<relatedEntity  name="account" pluralName="Sous-Comptes" pk="accountid" fk="parentaccountid" displayField="name" icon="gps_imgs/ico_subaccount.png"  UrlBody="main.aspx?etn=account" UrlBodyExtra="extraqs=id=" UrlSuffix="pagetype=entityrecord" />' +                             '</hierarchy>' +                         '</hierarchies>';     </script>

</head>

<body> <form id="form1" runat="server" style='height:100%'> <div id="silverlightControlHost"> <script type="text/javascript">          createSLObj(silverlightControlHost); </script> </div> </form> </body> </html>

The display is done in JavaScript in the variable named “slConf”. This variable contains data in XML.

Tags

  • Hierarchy :Represents the current entity

Attributes

  • entity : schema name of the entity
  • pk : primary key of the entity
  • icon: url

For information you can use your own pictures, for that you must import them into the CRM as a web resource.

If there are several attributes, you must use the separator ‘|’ between type and schema name and use a comma to separate different fields

Ex:

displayField= "name|string,estimatedvalue|Money,estimatedclosedate|System.DateTime,closeprobability|int,ownerid|EntityReference"

UrlBody, UrlBodyExtra ,UrlSuffix : are used to build record url

Tags

  • relatedEntity : represents an entity linked to the current record

Attributes

  • entity,pk,icon,displayField : see previous definition
  • fk : foreign key
  • pluralName:

relatedEntity: represents an entity linked to the current record

This code samples is provided "AS IS" without warranty of any kind.
We appreciate any feedbacks, so feel free to contact Remi BOIGEY | remib@microsoft.com

PAF

Comments

  • Anonymous
    May 01, 2011
    Excellent work from you guys! And special thanks to Remi for providing this useful add-on to Microsoft CRM 2011 :-)

  • Anonymous
    May 22, 2011
    Not working for me. Its giving blank and no error.

  • Anonymous
    September 25, 2011
    Hi, Nice article but when I tried to use it with the same steps you specified, I got nothing in the tab. It was all blank with no error in event viewer. However Silver-light 4.0 was installed on my machine. I tried on different machine and it worked. There doesn't seems to be any apparent differences in both machine. Any Idea? Thanks

  • Anonymous
    October 05, 2011
    The comment has been removed

  • Anonymous
    October 14, 2011
    Great article, but its showing a blank screen. Can you please double check? We have followed steps AS-IS. Thanks

  • Anonymous
    February 27, 2012
    Would this work with CRM Online too?

  • Anonymous
    April 03, 2012
    I followed all step as given by u.its not showing the required output...

  • Anonymous
    May 27, 2012
    Hi, Can you share the code for xap, please? Or, if not, will this be able to go upwards as well? Let's say the current account/contact has a parent. Will it show it on top of it? Thanks, Florin

  • Anonymous
    June 06, 2012
    Hi. How to make this recursively (to show more layers of related entities)?

  • Anonymous
    June 06, 2012
    For those who have commented that they're not seeing any content with this, be sure to check the "Pass record object-type code and unique identifier as parameters" checkbox at the bottom of the General tab in the Web Resource Properties dialog. This is a great looking tool but I'd like to be able to use it to display all my accounts and sub-accounts in a single tree. Can you provide some guidance on how to set up the HTML or modify the javascript to achieve this. I tried passing a null and empty guid to the control in the javascript but this causes an error.

  • Anonymous
    October 08, 2012
    Hi, Thanks for this useful and simple hierarchy viewer. It works fine for me but when I click in a related record (e.g. contact linked to parent account), it opens a wrong URL address missing ' / ' between the organisation name and 'main.aspx?etn=', so it looks like this: http://SERVER_NAME/ORG_NAMEmain.aspx?etc=.... Does it happen for you guys? Regards

  • Anonymous
    October 08, 2012
    *** Forget my previous post ***  still sleeping in London time, It was an easy change in the configuration webresource :P Thanks!

  • Anonymous
    December 09, 2012
    Hi Ramon, I have the same issue " it opens a wrong URL address missing ' / ' between the organisation name and 'main.aspx?etn='" Could you please tell me how you fixed it ? Thanks for your help.

  • Anonymous
    January 22, 2013
    The comment has been removed

  • Anonymous
    March 18, 2013
    Great work Remi. It just works. Trying to change the Language to English.

  • Anonymous
    April 21, 2013
    Hi Guys,       I deployed this in 3 different CRM online instances and one Onpremise and all worked fine but in another onpremise(workgroup) environment i was getting no result in the grid. So here are the steps

  1. Open the hierarchicalrelatedentity.js and at the bottom Change Silverlight.createObject(serverUrl + "WebResources/gps_ClientBin/SLHierarchicalRelatedEntity.xap",            divSLId, "slPlugin", To Silverlight.createObject(serverUrl + "/WebResources/gps_ClientBin/SLHierarchicalRelatedEntity.xap",            divSLId, "slPlugin",
  2. make sure that you enabled Anonymous access to .svc file. If you don't you will see an error in the Event longs. Check the error and correct it accordingly and make sure that you    Restart IIS after that. Please correct me if i'm wrong. Regards, Daniel.
  • Anonymous
    June 26, 2013
    I wonder what would be the performace of this application on real data?

  • Anonymous
    July 08, 2013
    Hello - this is great - thanks very much! Just wondering what I would need to do to have the company name expanded on load - to save me having to click on the company name to access the related entities? Thanks again,

  • Anonymous
    July 16, 2013
    Hello Remi, As Florin also asked above for the code. We wish to change it for same situation in order to show from parent records. Secondly, though one can open contacts, opportunities and activities by double clicking in the respective node, it is not possible to open a sub account in edit mode by double click. It always opens the sub hierarchy below the account instead of opening the edit form of sub-account

  • Anonymous
    October 22, 2013
    The comment has been removed

  • Anonymous
    January 10, 2014
    The comment has been removed

  • Anonymous
    February 07, 2014
    Hello, Is there any way of referencing an entity via a Many to Many relationship  - I tried using the relationship name as the foreign key and it didn't work. Any ideas very welcome, thanks.

  • Anonymous
    March 05, 2014
    Hi, In CRM 2013 the treeview does not appear - it flashes "100%" but then nothing appears in the Grid. There is no error message. This is a great solution and it would be a real shame if it did not function correctly in 2013. Any suggestions would be very welcome. Thanks again.

  • Anonymous
    March 12, 2014
    Hi, - not sure if you are checking these, but is there any easy way to exclude deactivated records from output? Thanks again.