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



Thursday, January 14, 2016

Create an Identity or incremental field based on Fiscal Year with a workflow in SharePoint

So I got a request from a customer who uses SharePoint 2013 that they need to create an identifier that looks something like this:  FY15 XXXX  


the XXXX is the identity number that starts from 1 at the new Fiscal year (the client's fiscal year starts in October).


This is an interesting problem that everyone encounters.  So I gave it a thought and came up with a solution that removes the concurrency concerns and other factors that could cause issues.


Here is the solution that's been tested and is working:


first create the column called: 
  • FiscalYear
    • number
    • Default: 
      • calculated value: =IF(MONTH(Today)>=10,YEAR(Today),YEAR(Today)-1)
      • This calculation is based on the fiscal year starting in October
  • IdentifierID
    • string or number:  I used String so that it is easier to append to my real id
    • Please note that the images have been modified so if you see UniqueID or UniqueID0, that was the original name of the field IdentifierID.


ok.  now the fun part of the exercise.  Creating a workflow on the list.


I created two stages:  Main and Sleep.  
  • Main:  does all the work, like call web service and calculate the ID
  • Sleep:  pauses for a minute for other items created previous to the current item to get their IdentifierID


Main:
  • variable to sleep = No
  • build the requestheader dictionary
  • call web service
    • https://MySharePointSite/_api/web/lists/getbytitle('NameOfList')/items?$top=1&$select=IdentifierID&$filter=(ID lt [%Current Item:ID%] and FiscalYear eq [%Current Item:FiscalYear%])&$orderby=ID desc
    • the key is here:
      • get the top 1 item
      • filter by ID less than currentItemID and FiscalYear equals CurrentItemFiscalYear
      • Order by ID desc
  • get results into listitems dictionary
  • get count of items in listitems dictionary
    • this is so that I know if it is the first item in the new Fiscal Year
  • then get the IdentifierID
  • Process the IdentifierID



  • go to End of Workflow


Sleep:
  • Pause for a minute for other workflow instances on previous items to complete
  • go back to main

Monday, November 23, 2015

Visual Studio Team Services Extensions from the Rangers

http://blogs.msdn.com/b/visualstudioalmrangers/archive/2015/11/18/visual-studio-extensions-from-the-rangers.aspx


With the Extensions feature going live this week as per the announcement during Connect, the VS ALM Rangers have been busy creating extensions. We have a total of 11 extensions that made it into the Visual Studio Team Services Marketplace when it launched, of which 4 are published under Microsoft DevLabs and the rest as community extensions. Here’s a little bit about them…

A list of DevLabs extensions:

Folder Management
Create new folders from the code explorer within the Team Web Access.
Team: Wouter de Kort & Abel Wang
Print Cards
Print cards from your backlog for use on a physical scrum board.
Team: Gordon Beeming (@GordonBeeming) & Robert MacLean (@rmaclean)
Test Case Explorer
An extension to explore test cases.
Team: Mattias Sköld & Mathias Olausson (@molausson + blog)
Work Item Visualization
Visualize relationships between work items from within the work item form.
Team: Taavi Koosaar (@melborp + blog + GitHub + email: taavik@melborp.net)

Wednesday, November 18, 2015

Full list of features for Visual Studio Team Services | Visual Studio TFS 2015

Use this end-to-end feature index to learn about all the features available to help you plan and track your projects and code, build, test, and release your software applications.

https://msdn.microsoft.com/library/vs/alm/overview/alm-devops-feature-index  

Wednesday, November 4, 2015

Fun with SharePoint 2013 workflows and custom outcomes

It looks like a bug but it makes sense that the Custom Outcome buttons do not appear if the two fields, Percent complete and the Task Status fields are hidden or they have been set to 100% and the task status is set completed.

This is some basic logic that Microsoft put in to make things easier to the normal users.   But i think this is killing the power users who are very knowledgeable with the workflow and process from the previous versions of SharePoint.

they should just remove this basic box or restraints put on to assist the users which Microsoft typically allowed the public to find way to put in rules and such but why only allow the customization of the workflow task form for Visual Studio and not SharePoint designer if they are going the route of dumb-ing down of the users with these silly rules but only allowing more advanced users with development knowledge to customize the workflow task form.

Interesting....

Also there is a bug in the workflow where the outcome variable in the task process is ordinal value instead of the string value of the custom outcome.
for example:
Approved
Canceled
Rejected
Re-Assigned

the values are returned to the task process outcome variable is:
0 = Approved
1 = Canceled
2 = Rejected
3 = Re-Assigned

This needs to be fixed.