Sunday, January 13, 2013

Generic solution to add missing associated views to the form navigation

This is the part 2 of my last blog Step by step tutorial to add the missing associated views to a CRM form. This blog will extend the solution to make it more generic. In the previous solution we have to add the relationship name in HTML web resource, which means  that we have to create multiple HTML web resources if we want to add multiple associated views in the system.
I have updated the solution to pass the relationship name as parameter(query string) to the HTML resource. This way we can use the same HTML web resource as many times as we want.

Here is the updated code for the HTML web resource.
 <html xmlns="" >  
   <title>Untitled Page</title>  
   <style type="text/css">html,body{font-family: Segoe UI, Tahoma, Arial;background-color: #d6e8ff;border: 0px; margin: 0px; padding: 0px;}</style>  
   <script type="text/javascript" language="javascript">  
       //get the context  
       var Xrm = window.parent.Xrm;  
       //get the current object id  
       var oId =;  
       //get the object type  
       var oType = Xrm.Page.context.getQueryStringParameters().etc;  
       //set Relationship Name  
       var relName = getDataParam();  
       if (relName != "not found") {  
         //building a url  
         var sUrl = "/userdefined/areas.aspx?oId=" + oId + "&oType=" + oType + "&pagemode=iframe&security=852023&tabSet=" + relName;  
         //get relative path with orgname as required  
         var relativeUrl = Xrm.Page.context.prependOrgName(sUrl);  
         window.location = relativeUrl;  
       else {  
       //Most of this code is from sdk dataparams example  
       function getDataParam() {    
       //Get the any query string parameters and load them into the vals array  
         var vals = new Array();  
         if ( != "") {  
           vals ="&");  
           for (var i in vals) {  
             vals[i] = vals[i].replace(/\+/g, " ").split("=");  
           //look for the parameter named 'data' and return relationship name  
           for (var i in vals) {  
             if (vals[i][0].toLowerCase() == "data") {  
               var relationship = decodeURIComponent(vals[i][1])  
               relationship = relationship.replace(/\+/g, " ")  
               return vals[i][1];  
           } //end for loop  
           return "not found";  
         else {  
           return "not found";  
       }// end function  
       function noParams() {  
         var message = document.createElement("p");  
         message.innerText = "No data parameter was passed to this page";  

How to call HTML web resource

  1. Add the navigation link to the form. The navigation link properties dialog will look like the following screen shot.

  2. Choose the name for the navigation link.
  3. Select an icon for the link.
  4. Select  “External URL” instead of using the web resource. Use the relative path for the web resource and pass the relationship name as query string parameter as  shown in the screen shot above.
  5. Save and publish the changes and test the solution.
There you go now you can use the same HTML resource to add as many missing associated views as you want.

1 comment:

  1. Hi!
    New Navigation Link is not visible for non admin users. Is there any permissions that should be granted to users?
    I'm adding associated Leads view to Campaign. Despite the fact that non-admin user can read all campigns and leads, navigation link is not displayed.