Friday, February 19, 2016

SharePoint 2013 workflow can't terminate using UI: Terminate using powershell

Had a strange situation where the workflow instance will not terminate using the UI.   When I click on the status, it just gave an error so after tracking down what the error was in the uls which didn't give too much information but that something was a null where a value was expected: 


Getting Error Message for Exception System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentNullException: Value cannot be null.


at Microsoft.SharePoint.Workflow.SPWorkflow.retrieveSchema(Schema schemaIndex)


at Microsoft.SharePoint.Workflow.SPWorkflow.retrieveSchemaGuid(Schema schemaIndex)


at Microsoft.SharePoint.Workflow.SPWorkflow.get_AssociationId()


at Microsoft.SharePoint.Workflow.SPWorkflow.GetReadOnlyParentAssociation()


at Microsoft.SharePoint.Workflow.SPWorkflow.get_ParentAssociation()
.......




Here is the powershell to terminate the workflow instance that is suspended.  a slightly modified script from http://social.technet.microsoft.com/wiki/contents/articles/23850.sharepoint-2013-workflow-management-starting-a-workflow-using-powershell.aspx






Add-PSSnapin *sharepoint* -ErrorAction SilentlyContinue


$sourceWebURL = '<url to your web>'
$sourceListName = '<list name>'
$TargetWorkflow = '<workflow name>'
$itemId = <Id of the item the workflow you want to stop>


$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]

#-- Getting a Workflow manager object to work with.
$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($spSourceweb)
#-- Getting a Workflow instance in order to perform my commands.
$wfis=$wfm.GetWorkflowInstanceService()


$wfinstances = $wfis.EnumerateInstancesForListItem($spSourceList.ID, $itemId)
foreach($wfi in $wfinstances)
{
    if($wfi.Status -eq "Suspended")
    {
        $wfi
        $wfis.TerminateWorkflow($wfi)
    }
}

Tuesday, February 2, 2016

SharePoint 2013 Usage service trouble shooting

Recently my farm encountered an issue with the Usage statistics not showing up in my reports but the data was still getting captured in the database.  


first thing to check are some status for your service application


$app = Get-SPServiceApplication -Identity '{Your usage service app guid}'


the get the usageapplication for some properties and status:


$ua = Get-SPUsageApplication -Identity $app


$ua.Status




if everything looks good, then make sure your usage definitions have Receivers:


$aud = Get-SPUsageDefinition | where {$_.Name -like "Analytics*"}


$aud | fl


$prud = Get-SPUsageDefinition | where {$_.Name -like "Page Requests"}


$prud | fl




Look at your results to make sure you have the following
-------------
EnableReceivers : True

Receivers : {Microsoft.Office.Server.Search.Analytics.Internal.AnalyticsCustomRequestUsageReceiver}





EnableReceivers : True

Receivers : {Microsoft.Office.Server.Search.Analytics.Internal.ViewRequestUsageReceiver}






finally if that's all good then unprovision your usage app and then go provision using Central admin:


first to unprovision:


$app = Get-SPServiceApplication -Identity '{Your usage service app guid}'
$app.Unprovision()


then in Central Admin, Monitoring, Configure usage and health data collection
-enable
-check items you want collected
-database name
-windows auth
-Ok


-----------------------------------------------------------------------------------------------------------------
Some very helpful links:


http://blogs.msdn.com/b/sharepoint_strategery/archive/2015/04/15/sp2013-search-index-health-reports-for-monitoring-and-troubleshooting.aspx




https://gallery.technet.microsoft.com/scriptcenter/Builds-SP-Search-2013-10d72a25


https://gallery.technet.microsoft.com/scriptcenter/Get-SPSearchTopologyState-b7452c6a