Click through to CRM records from SSRS custom report for Microsfot Dynamics CRM 4. Linking information on SQL Reporting Services custom CRM reports to Dynamics CRM 4 records and opening them up from within the report.

If you are writing a custom report – SQL Server Reporting Services (SSRS) report for Microsoft Dynamics CRM 4, you might want to add the functionality (sql expression) to click through to a record. This can be applied to some or all information shown on the report, so that if you click on the information text box, you open up the corresponding CRM record in a new window such as: click on sub-account in the sub-accounts list to open this sub-account CRM record, or the same for contact, opportunities and so on.

To do this, right click on the text box in where you will be putting the expression and the value to be clicked on, and click on Texbox properties. On there click on Actions on the left, select last option “Go to URL” and in the expression box type the following query expression

=IIF(IsNothing(Parameters!CRM_URL.Value),system.dbnull.value,Parameters!CRM_URL.Value & "?ID={"&Fields!Accountid.Value.ToString()&"}&OTC=1")
/*Replace "&Fields!Accountid" with the ID of the corresponding record */
/*you want to be open, so contactid, opportunityid or any other custom entity id field*/
/*Also replace OTC value above with the Entity Object type Code (OTC) value*/

You can get any entities OTC value from the “EntityView” view or for the full list of all system entities type codes, read this MSDN article: http://msdn.microsoft.com/en-us/library/bb887791.aspx. Obviously you will need to get the OTC value for your custom entities from the “EntityView” view from your Dynamics CRM database. You can use a query similar to the following:

select entitytypecode from entityview where entityname = 'account'

This sql expression can work with any entity either system (cusomisable) or custom entity.

Hide tab in any entity form in Microsoft Dynamics CRM 4 using Javascript in onLoad event of the form.

In many cases, you might want to remove one of the tabs of an entity form in Microsoft Dynamics CRM 4. This can be specifically helpful in two cases:

1- If you want to hide and show tabs depending on a picklist value selection such as contact type: Hide Work details if contact is of type internal contact for example

2- If you want to hide the Administration and Notes tab from an entity form while these tabs are locked and cannot be removed from the entity form.

To hide a tab in an entity form, you can use the following Javascript sample script:

//---------------------------Hide a tab by passing tab name to the function
HideTab('Administration');
//replace "Administration" with your tab name
function HideTab (tabText)
{
 var tab = FindTab(tabText);
 if (tab)
 {
  tab.style.display = "none";
 }
}
function FindTab(tabText)
{
 var tabBar = document.getElementById("crmTabBar");
 if (tabBar)
 {
  var tabs = tabBar.childNodes;  

  for (var i = 0, len = tabs.length; i < len; i++)
  {
   var currentTab = tabs[i];
   if (currentTab.innerText === tabText)
   {
    return currentTab;
   }
  }
 }
}
//-----------------end of script--------

Maxjerin has added a new code suggestion. Maxjerin’s code hides a tab based on the onChange event of a field on the form. If the primary contact “name” field is maxjerin, the tab is displayed. Otherwise the tab is hidden.

I have updated the post to include Maxjerin’s code – Thanks Maxjerin:

Here is the code that I used to HIDE/UNHIDE a tab when I wanted to show it for only one particular user and hide for others. The code includes some alert messages just for debugging purpose which you might find useful to understand the code. You may remove them once done.

This section goes into the onChange section of the Primary Contact lookup field

if (crmForm.all.primarycontactid.DataValue == null )
{
var strTabStatus = TabStatus(‘Profile’);
if ( strTabStatus == ”)
{
alert(“Primary Contact none, hiding the tab”);
HideTab(‘Profile’);
}
}
else if (crmForm.all.primarycontactid.DataValue[0].name == ‘maxjerin’)
{
alert(“Primary Contact p f, unhiding the tab”);
UnHideTab(‘Profile’);
//replace “Administration” with your tab name
}
else if (crmForm.all.primarycontactid.DataValue[0].name != ‘maxjerin’)
{
var strTabStatus = TabStatus(‘Profile’);
if (strTabStatus == ” )
{
alert(“Primary Contact other than maxjerin, Hiding the tab”);
HideTab(‘Profile’);
}
}
function HideTab (tabText)
{
var tab = FindTab(tabText);
if (tab)
{
tab.style.display = “none”;
}
}
function UnHideTab (tabText)
{
var tab = FindTab(tabText);
if (tab)
{
tab.style.display = “”;
}
}
function FindTab(tabText)
{
var tabBar = document.getElementById(“crmTabBar”);
if (tabBar)
{
var tabs = tabBar.childNodes;
for (var i = 0, len = tabs.length; i < len; i++)
{
var currentTab = tabs[i];
if (currentTab.innerText === tabText)
{
return currentTab;
}
}
}
}
function TabStatus(tabText)
{
var tabBar = document.getElementById(“crmTabBar”);
if (tabBar)
{
var tabs = tabBar.childNodes;
for (var i = 0, len = tabs.length; i < len; i++)
{
var currentTab = tabs[i];
if (currentTab.innerText === tabText)
{
if (currentTab.style.display == ‘none’)
{
alert(“tab already hidden, TAB NAME: ” + currentTab.innerText );
return “none”;
}
else
{
alert(“tab is visible, TAB NAME: ” + currentTab.innerText );
return “”;
}
}
}
}
}
//-----------------------------------------------------------------------
Please comment below if you have any feedback or anything to add.
Thanks