Thursday, November 24, 2016

Force update analytics components timer job

Issue: The popular items report for the document library are updated every 24 hrs and we cannot get the recent hits updated immediately.

Workaround: Following is the workaround to get the recent hits updated in the most popular items report for a document library

Prerequisite: Make sure that Reporting feature and Popularity Trends/usage analytics is enabled for the site

1. Make sure that the Search Analytics timer job is started.
$analyticsJob = Get-SPTimerJob -Type Microsoft.Office.Server.Search.Analytics.AnalyticsJobDefinition
$searchanalytics = $analyticsJob.GetAnalysis("Microsoft.Office.Server.Search.Analytics.SearchAnalyticsJob")

  1. Trigger the events by opening and downloading some files from document library

  1. Make sure that the usage files @ C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\LOGS\RequestUsage are updated with the event details.

  1. Events can be imported from usage to Event store by running the Timer Job manually using following PowerShell script

$usagejob = Get-SPTimerJob -Identity ("job-usage-log-file-import")

  1. Make sure that the event store (C:\Program Files\Microsoft Office Servers\15.0\Data\Office Server\Analytics_<GUID>\EventStore)  is updated with the event

  1. Copy the current data event store logs to a custom folder location. In this example we have copied the logs to following location
    15 Hive\Data\Office Server\Analytics_<GUID>\EventStore\20161124\MyEvents

  1. Run the following PowerShell script to start the usage analytics

$uajob = get-sptimerjob -type
$uajob.StartAnalysis("\\ilinksys-121\Office Server\Analytics_abce7b74-9002-404b-92b2-126bcddf451e\EventStore\20161124\MyEvents")

Check the most popular items report once the job state is complete and you notice that the recent events are updated.

Thursday, November 17, 2016

Retrieve Popular items Programmatically In SharePoint using SOM


In this article, we’ll see how to retrieve popular items based on view counts programmatically using SOM.


Make sure that you have enabled the reporting feature under site collection features in the site to see the popular documents.

The following lines of code retrieve the data and update the results in a Data table.

using System;
using System.Linq;
using Microsoft.SharePoint;
using Microsoft.Office.Server.Search.Query;
using System.Data;

namespace GetPopularItems
   class Program
       static void Main(string[] args)
           DataTable table = new DataTable();
table.Columns.Add("ItemID", typeof(Int32));
           table.Columns.Add("Name", typeof(String));
           table.Columns.Add("Recent", typeof(Int32));
           table.Columns.Add("Views", typeof(Int32));

           string siteurl = "http://SiteURL/";
           string docLibURL = "http://SiteURL/Shared%20Documents";

           using (SPSite siteCollection = new SPSite(siteurl))
               using (SPWeb rootWeb = siteCollection.OpenWeb())

                   KeywordQuery keywordQuery = new KeywordQuery(siteCollection);
var properties = keywordQuery.SelectProperties; properties.Add("ListItemID");
                   keywordQuery.QueryText = "Path:"+ docLibURL;
                   SearchExecutor searchExecutor = new SearchExecutor();
                   ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
                   var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
                   ResultTable resultTable = resultTables.FirstOrDefault();
                   DataRowCollection dataTable = resultTable.Table.Rows;
                   for (var i = 1; i < dataTable.Count; i++)
                       DataRow datarowObj = table.NewRow();
datarowObj["ItemID"] = resultTable.Table.Rows[i][(resultTable.Table.Columns["ListItemID"]).Ordinal];
                       datarowObj["Name"] =  resultTable.Table.Rows[i][(resultTable.Table.Columns["Path"]).Ordinal];
                       datarowObj["Recent"] = resultTable.Table.Rows[i][(resultTable.Table.Columns["ViewsRecent"]).Ordinal];
                       datarowObj["Views"] = resultTable.Table.Rows[i][(resultTable.Table.Columns["ViewsLifeTime"]).Ordinal];

Monday, November 14, 2016

The administration service is running so all administration jobs will be run in the timer service.

Environment: SharePoint 2013

Scenario: Tried to run the following powershell cmdlet to execute all administrative timer jobs immediately rather than waiting for the timer job to run.


 Issue: Command failed and got following error message

 Error: Start-SPAdminJob : The administration service is running so all administration jobs will be run in the timer service.


Go to Services.msc and stop the SharePoint Administration service and try again. Start the service once the command is completed executing.

 Alternatively use net stop SPAdminV4 and net start SPAdminV4 cmdlet to stop and start the SharePoint Administration service

Friday, November 11, 2016

we don't have data for this item right now. Please try again later.

Environment: SharePoint 2013 Enterprise On-Premise
Scenario: Trying to check the Popularity Trends report and most popular item in the document libraries.
Issue: we got the below error message when tried to export the popularity report or most popular item report by clicking the Usage under Usage Reports section.
Error: we don't have data for this item right now. Please try again later.
Resolution: Check if the SharePoint Timer job is running and Search Service Application is started. Create and configure Search Service application if not started already.
Refer to the following blog post for configuring Popularity trends.