Monday, February 11, 2013

Customizing the SharePoint 2013 Developer Dashboard using custom scripts

Wow Stefan Gobner has shared a wonderful article on Customising Dev Dash in 2013.

In SharePoint 2013 Dev dash has helped the admins to help troubleshoot a lot of performance issues .
 The Developer Dashboard can now be extended by injecting custom JavaScript code into the developer dashboard window.

Two steps are necessary to achieve this:

1.Custom JavaScript code, which interacts with the developer dashboard DOM, has to be added to a script file that can be accessed from the Developer Dashboard page. E.g. by placing the script file into the _layouts/15 directory.

2.The custom script file(s) have to be registered to be loaded into the Developer Dashboard page.
Below is a short example, which hides the ULS tab in the Developer Dashboard. This example also shows how to use jquery within the Developer Dashboard.

Create the custom logic in a script file

Create a "hideULSTab.js" inside the layouts/15 directory (program files\common files\microsoft shared\web server extensions\15\template\layouts) and add the following script code to it:
// register a code block that runs after the page is loaded
$(document).ready(function()
{
   // iterate over all tabs (identified by CSS class "ms-dd-Tab")
   $('.ms-dd-Tab').each(function(index, para)
   {
      // look for the tab which has "ULS" title
      if ($(para).text().indexOf("ULS") !== -1)
      {
         // hide the title
         $(para).hide();
      }
   });
});

Register the script files with the Developer Dashboard

Our custom script code requires the jquery library – so we have to register two script files with the developer dashboard. That can be done using the following powershell commands:

$contentSvc = ([Microsoft.SharePoint.Administration.SPWebService]::ContentService)
$DevDashboardSettings = $contentSvc.DeveloperDashboardSettings
$DevDashboardSettings.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On

$DevDashboardSettings.userscripts.Add("http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.0.min.js")
$DevDashboardSettings.userscripts.Add("/_layouts/15/hideULSTab.js")

$DevDashboardSettings.Update()

As you can see we are registering two different script files: first the jquery library from an external site and second the script file we created earlier.

The powershell script will also enable the Developer Dashboard by setting the DisplayLevel to On.

http://blogs.technet.com/b/stefan_gossner/archive/2013/01/23/customizing-the-sharepoint-2013-developer-dashboard-using-custom-scripts.aspx

No comments:

Post a Comment

Users cannot see the checked out files in the folder/ library

I Came across a Issue today wherein the user opened a ticket for the below issue Issue : Users cannot see the checked out files in the fo...