1

I am planning to have a workflow in SharePoint 2013, run a weekly loop from start to end dates. This will run fine normally. However how about when the process stops due to like the server going down. Thus what do you do in that case?

Basically:

  1. How do you detect when that kind of error occurs? How do you write to log file and/or send out a email if that is possible.

  2. How do you restart the process from when the process stopped executing at?

All I know is that you can set the process to be manually started.

1 Answer 1

2

You can do this whith powershell:

Start a workflow:

Add-PSsnapin Microsoft.SharePoint.PowerShell
$SPAssignment = Start-SPAssignment
$web = Get-SPWeb "http://YourSharePoint/Site"
$site=Get-Spsite "http://YourSharePoint"
$list = $web.Lists["Your List"]
foreach($item in $list.Items)
{                               
        $manager=$site.WorkFlowManager
        $culture = [System.Globalization.CultureInfo]::InvariantCulture
        $association=$list.WorkFlowAssociations.GetAssociationByName("Worklflow Name", $culture)
        $data=$association.AssociationData
        $wf=$manager.StartWorkFlow($item,$association,$data,$true)

}
Stop-SPAssignment $SPAssignment

And to monitore workflow status (SharePoint Online):

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")    

 Function GetWorkflowStatus([Microsoft.SharePoint.Client.List]$list,[int]$listItemId, [string]$workflowName)
 {
     $context = $list.Context
     $listItem = $list.GetItemById($listItemId)
     $context.Load($listItem.FieldValuesAsHtml)    
     $workflowStatusField = $listItem.ParentList.Fields.GetByTitle($workflowName)
     $context.Load($workflowStatusField)
     $context.ExecuteQuery()    
     if ($listItem.FieldValuesAsHtml[$workflowStatusField.StaticName] -ne $null)
     {
         $statusValue = $listItem.FieldValuesAsHtml[$workflowStatusField.StaticName]
         Write-EventLog -LogName Application -Source 'Application Error' -Message $statusValue -EventId 2337 -EntryType error;
     }
     return $null
 }

See the erros codes of workflows.

2
  • My company uses SharePoint in the cloud. Thus would I need to write code like you suggested? If I do need to write the code, can I just use a tool, change some settings, change a config file without writing code? Jan 13, 2015 at 16:49
  • I recommend doing with powershell. You will probably need to write code. Jan 13, 2015 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.