Various SharePoint developer tools

In this SharePoint 2013 tutorial, we will discuss various useful tools that we can use while debugging in SharePoint. Here we will see about Developer dashboard, ULS Viewer, SharePoint Log viewer, CAML query builder, IE Developer Tools, and Event Viewer.

Developer Dashboard

The Developer Dashboard use to show performance and tracing information for a SharePoint page in control on the page itself. This gives us information about execution time, log correlation ID, critical events, database queries, service calls, SPRequests allocation, and web part events offsets, etc.

By default the Developer Dashboard is disabled. We can enable it by using Windows PowerShell or by using the Server-side object model.

Enable Developer Dashboard using PowerShell

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction "SilentlyContinue"
$dash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$settings = $dash.DeveloperDashboardSettings
$settings.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$settings.Update()

DisableDeveloper Dashboard using PowerShell

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction "SilentlyContinue"
$dash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$settings = $dash.DeveloperDashboardSettings
$settings.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::Off
$settings.Update()

Here is the code to enable developer dashboard using object model code:

Enable Developer Dashboard using Server Object Model

SPDeveloperDashboardSettings settings = SPWebService.ContentService.DeveloperDashboardSettings;
settings.DisplayLevel = SPDeveloperDashboardLevel.On;
settings.TraceEnabled = true;
settings.Update();

Disable Developer Dashboard using Server Object Model

SPDeveloperDashboardSettings settings = SPWebService.ContentService.DeveloperDashboardSettings;
settings.DisplayLevel = SPDeveloperDashboardLevel.Off;
settings.TraceEnabled = true;
settings.Update();

Read a SharePoint 2013 tutorial on: Developer Dashboard in SharePoint

You can see the dashboard like below:

sharepoint developer tools sharepoint developer dashboard
sharepoint developer tools : sharepoint developer dashboard

Read some SharePoint 2013 tutorials:

ULS Viewer for SharePoint 2016/2013

ULS Viewer is a useful tool to develop an application, expose in-depth information for debugging. ULS writes events to the Trace Log and stores them in the file system.

If you are working with some custom solutions or you face any issue or unexpected behaviour then to debug more ULS logs are very much helpful. By default, SharePoint maintains ULS logs for every request.

Actually, ULS logs is the first place for a developer or an administrator to check out.

ULS logs are stored on the file system of every SharePoint server in the <Program Files Directory>\Common Files\Microsoft Shared\Web Server Extensions\16\LOGS folder.

Learn how to Change ULS Log Location in SharePoint 2013/2016?

Once you download it will download as a zip file. Unzip it and you will get a file as ulsviewer.exe. Double click on the file to open.

uls viewer sharepoint
uls viewer sharepoint

Then browse to the ULS file where the logs are there from the open file button. Once you will open a file it will look like below:

uls viewer sharepoint 2013
uls viewer sharepoint 2013

Then you can use the filter button to filer based on various conditions.

uls viewer sharepoint 2016
uls viewer sharepoint 2016

This way you will be able to find log details.

Read some SharePoint 2013 tutorials:

SharePoint LogViewer

SharePoint LogViewer is a very good tool to view ULS logs. This GitHub tool is very efficient and has la ot of options like view real time logs, export logs, show logs from multiple files, filter based on various filter columns. Also, this tool supports Moss 2007, SharePoint 2010 as well as SharePoint 2013. This is a windows application to for reading and filtering URL logs.

Open Log Files

To see the existing log click on the Open Files button like below: Then you can browse the log file and see the log details.

SharePoint log viewer
SharePoint log viewer

View Real Time Logs

To view real time logs, click on the “Start Live Monitoring” button as shown in the fig below:

SharePoint 2013 log viewer
SharePoint 2013 log viewer

Export Logs

We can also export logs by click on the “Export Log Entries” button as shown in the fig below:

SharePoint 2016 log viewer
SharePoint 2016 log viewer

Filter Logs SharePoint LogViewer

Once you load any log file you will be able to filter logs based on various criteria like Correlation id, area, categoryid, eventid etc. It will be like below:

sharepoint 2010 log viewer
sharepoint 2010 log viewer

Change Columns in SharePoint LogViewer

By default, it will display all the columns in the UI. If you want to show only few selected columns then you can click on the Setting icon and then in the Settings dialog box you can check and uncheck columns as shown in the fig below:

sharepoint developer tools
sharepoint developer tools SharePoint 2013 log viewer

Check out more in the below article:

Read some SharePoint 2013 tutorials:

CAML Query Builder

CAML (Collaborative Application Markup Language) is an XML-based query language that helps you querying lists and libraries in SharePoint. This windows application has been developed to ease the work of a SharePoint 2013 and SharePoint Online developer.

This tool will help you create and test your CAML Queries. This edition of the tool uses the Client Side Object Model to connect to any remote SharePoint 2013 or SharePoint online environment.

The following prerequisites are required: Microsoft .NET Framework 4.5 (x86 and x64) If these components are already installed, you can launch the application now. Otherwise, click the button below to install the prerequisites and run the application.

Microsoft.SharePoint.SPQuery object has Query property that accepts a CAML fragment, which defines the query to be performed. A ViewFields property defines the fields to return. The CAML fragment may contain Where, OrderBy, and GroupBy elements.

<where>
</Where>
<orderby>
<FieldRef/>
</OrderBy>
<groupby>
<FieldRef/>
<groupby>

Where condition may contain: And,BeginsWith,Contains,Eq,FieldRef,Geq,GroupBy,Gt,IsNotNull,IsNull,Join, Leq,Lt,Neq, Now,Or etc.

<Where>
<Lt>,<Gt>,<Eq>,<Leq>,<Geq>,<Neq>,<BeginsWith>,<Contains>,<IsNotNull>,<IsNull>
<FieldRef Name=”FieldName”/>
<Value>[Test Value], Today</Value>
</Lt>,</Gt>,</Eq>,</Leq>,</Geq>,</Neq>,</BeginsWith>,</Contains>,</IsNotNull>,</IsNull>
<And>,<Or>
<Lt>,<Gt>,<Eq>,<Leq>,<Geq>,<Neq>,<BeginsWith>,<Contains>,<IsNotNull>,<IsNull>
<FieldRef/>
<Value>[Test Value], Today</Value>
</Lt>,</Gt>,</Eq>,</Leq>,</Geq>,</Neq>,</BeginsWith>,</Contains>,</IsNotNull>, </IsNull>
</And>,</Or>
<Where>
<OrderBy>
<FieldRef/>
</OrderBy>
<GroupBy>
<FieldRef/>
<GroupBy>
SPQuery query = new SPQuery;
query.Viewfields = @"<fieldref Name='Title'/><fieldref Name='Expires'/>";
query.Query =
@"<where>
<lt>
<fieldref Name='Expires'/>
<value Type='DateTime'><Today/></Value>
</Lt>
</Where>";
SPList list = SPContext.Current.Web.Lists.TryGetList("Announcements");
SPListItemCollections items = list.GetItems(query);

Double click on the file which will install and open U2U CAML Query Builder. You can connect to both on-premise as well as SharePoint Online sites.

To login to the On-premise site, choose the radio button Connect to SharePoint On-Premises and you can choose Credentials of the current user like below:

sharepoint caml query builder
sharepoint caml query builder
sharepoint developer tools caml query builder
sharepoint developer tools caml query builder

You can click on the Execute query button to see the result.

sharepoint caml query builder
sharepoint caml query builder

Example:

string s = "No record";
SPWeb web = new SPSite("http://mypc:29024/sites/SPTraining/").OpenWeb();
SPQuery query = new SPQuery();
query.ViewFields = @"<FieldRef Name='Title' /><FieldRef Name='Expires' />";
query.Query =
@"<Where>
<Lt>
<FieldRef Name='Expires'/>
<Value Type='DateTime'><Today/></Value>
</Lt>
</Where>";
SPList list = web.Lists.TryGetList("MyCompanyAnnouncement");
SPListItemCollection items=list.GetItems(query);
if(items.Count>0)
{
foreach (SPListItem Item in items)
{
s += Item.Title + "\n";
}
}
label5.Text = s;

IE Developer tool

IE developer tool is another approach to debug client-side code (HTML/CSS also). You can use F12 to start and then you can use F10 to proceed further.

Check out more in the below article:
https://msdn.microsoft.com/en-us/library/gg589507%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

Event Viewer

This is one of the popular places to search for SharePoint errors.

You can open this by using the command like this:

Start -> Run and then enter eventvwr and click on Ok. This will open the Event Viewer window.

It has a separate section for SharePoint with the name Windows SharePoint Services. Apart from this, you can also check in the Windows Logs -> Applications section for errors.

sharepoint event viewer
sharepoint event viewer

Debugging JavaScript in Google chrome SharePoint

Let us see, how to debug JavaScript in Google chrome for SharePoint client-side code (jsom).

JavaScript Debugging

Debugging is the process of finding out the bug and find out the error in the JavaScript code.

Sometimes our code contains some syntactical error and logical error so the bug will appear but JavaScript provided some built-in method. By using the built-in function we can find out our error and we can work on it.

Console.log() method:

The console.log() is used for debugging purposes. When our code contains any bug then also we can see the output in the console.

Below is our HTML code and JavaScript code.

<!DOCTYPE html>
<html>
<script src=”https://onlysharepoint2013.sharepoint.com/sites/Raju/tsinfo/SiteAssets/HtmlJsCssFiles/ConsoleFunction.js”></script>
<body>
<h1>JavaScript debugging using console.log() method</h1>
<p>Clicking on Fn+F12 to open devlopertool and then to see the error  by clcik on console from devloper tool</p>
</body>
</html>
a = 3;
b = 6;
c = a*b;
console.log(c);

In the console, we can see our output. We will get the console from the browser menu in the developer tool like below. In shortcut, we get the developer tool by clicking on Fn+F12.

In JavaScript, we are not declaring the variable.

Debugging JavaScript in Google chrome SharePoint
Debugging JavaScript in Google chrome

How to set a breakpoint in the JavaScript code?

The use of breakpoint is it will stop the execution at a particular point. Where we are using the breakpoint in a code where we are using the breakpoint from that point code will not execute.

Debugger keyword is a type of breakpoint.

When the debugger keyword is encountered it will call the debugger method. When our code is error-free then the debugger keyword will not affect the code.

I hope this tutorial helps to learn sharepoint developer tools.

Related Tutorials:

>