Tuesday 31 January 2012

Creating embedded grid between parent & child entities in CRM form

Last time, I spent 2 days to figure out how to create an embedded-grid showing "child" entities which are related to a parent entity as the following picture:


As you see, in Campaign Activity entity (which is a parent entity), there are many Email entities (which are related entities). So now, I would like to create a navigation when clicked will show you related entities like that.

The key thing needed to understand is: actually, when you create a relationship bet when 2 entities (such as: Campaign Activity & Email), there is an exsiting "tabset" which stores all related entities created. The navigation link just let us to that tabset only. So the task now is: building url to the tabset.

Here is the javascript how to build the navigation link to get the embedded-grid:
function passURLtoNavigation()
{ //Gets navigation item
   var items = Xrm.Page.ui.navigation.items.get();
   for (var i in items)
    {
       var item = items[i];
      var label = item.getLabel();
      if (label == "Email Created")
          { var navId = item.getId();
            var navItem = document.getElementById(navId);
            if (navItem != null && navItem != undefined)
              { var serverUrl = location.protocol + '//' + location.host + '/' +     Xrm.Page.context.getOrgUniqueName();
          var oId = Xrm.Page.data.entity.getId();
          var oType = Xrm.Page.context.getQueryStringParameters().etc;
          var security = "852023";
          var tabSet = "//here is your relationship name";       
                   //building the URL for the navigation link
                   var navUrl = encodeURI(serverUrl + "/userdefined/areas.aspx?oId=" + oId + "&oType=" + oType + "&security=" + security + "&tabSet=" + tabSet);
                   navItem.onclick = function () { loadIsvArea(Mscrm.CrmUri.create(navUrl), false ); };
}
}
}
}

So now, you have the subgrid as shown in the first picture. I hope it will be helpful.

Friday 20 January 2012

CRM 2011 Customization - Decrypt default Javascript files in CRM Server

 So it's this, the first blog !!!

Two weeks ago, during the time writing a Javascript to customize a CRM button, I found out the way how to decrypt the default Javascript files in CRM server which are might be helpful for you to refer and understand how CRM functions were built.

What I wanted is tracing what they did when building the Campaign Activity entity. Then I exported the default solution and looked what they did with the entity. Opening the customization file, you can see in the picture, there are 3 javascript files applied for it:



As you see, the "CamPaignActivity_main_system_library" was located somewhere in the server and defined in Javascript by "$webresource". It took me several hours to find where actually the file was. Then, the tip is very simple, CRM itself has a database which store all things in the system inside. And in the database, there is an view named "WebResource" where you could look for any webresource belongs to your CRM system. So what you need to do is: opening SQL Server --> CRM Database --> put the query to find WebResource View.

Look at the following pic to refer:


So now I find out the content of the javascript file ! But this content is encrypted. Actually, they just converted them into a different kind of string. Then you need to make some code to decrypt in order to take the real javascript content. The C# code below:

 protected void Button1_Click(object sender, EventArgs e)
        {       
            byte[] binaryData = System.Convert.FromBase64String("//here is your javascript encripted content//");
            string x = System.Text.Encoding.ASCII.GetString(binaryData);              
            Response.Write(x);      

        }

So now, you had the javascript file with decrypted content. I hope it's helpful ;)