question

msdc avatar image
0 Votes"
msdc asked sharatha commented

Best way to handle/archive Workflow History List

Hello,

I am running into issues with a custom SharePoint list where the workflow seems to be erroring but I am unable to access the workflow history list to see what has not run properly for each item. My list view threshold is set to 15,000 but the workflow history list is at 25,000. I am leaning toward just totally wiping out every item in the history list but I know that means i lose history on all workflow history for each item submitted which I dont want. Is there anything possible for me to do besides using powershell to totally empty out the list. Of course I could increase threshold to 30,000 but don't want that. I just hate not being able to see anything in the workflow history list to see what has completed or errored out.

Thanks for any help

office-sharepoint-server-administrationoffice-sharepoint-server-developmentoffice-sharepoint-server-itpro
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EmilyDu-MSFT avatar image
0 Votes"
EmilyDu-MSFT answered msdc commented

@Dez-4361
The answer provided by sharatha can be used as a workaround.

Based on your description, I understand that you want to purge Workflow History list. Here’s PowerShell for you.

Note: The $cutoffDate determines which items to keep. As configured, the cutoff date will be current date - 1days. Any items older than 1days will be removed. You can set $cutoffDate according to your requirement.

 $webURL = "your site collection URL"
 $cutoffDate = (Get-Date).AddDays(-1)
     
 Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
     
 Write-Host "`n- Opening web site $webURL"
 $web = Get-SPWeb $webURL -ErrorAction SilentlyContinue
 if (!($web)) {
   Write-Host -ForegroundColor Red "- Unable to open web site $webURL"
   Exit
 }
     
 Write-Host "- Opening workflow history list"
 $list = $web.lists["Workflow History"]
 if (!($list)) {
   Write-Host -ForegroundColor Red "- Unable to open Workflow History list"
   $web.Dispose()
   Exit
 }
     
 DO {
   $cutoffDateF = "{0:MM/dd/yyyy}" -f $cutoffDate
   Write-Host "- Looking for items where 'Date Occurred' <= $cutoffDateF"
   Write-Host
   $rowlimit = 100
   $caml="<OrderBy><FieldRef Name='ID' Ascending='TRUE' /></OrderBy><OrderBy><FieldRef Name='ID' /></OrderBy>"
   $camlQuery = New-Object Microsoft.SharePoint.SPQuery
   $camlQuery.RowLimit = $rowLimit
   $camlQuery.Query = $caml
   $items = $list.GetItems($camlQuery)
     
   If (!($items)) {
     Write-Host -ForegroundColor Red "- No items to process"
     Break
   }
     
   $itemTotal = $items.Count
   $itemCurrent = 1
   $itemsDeleted = 0
   Write-Host "- Items to process: $($itemTotal)"
   $timeStarted = Get-Date
   For ($i=$items.count-1; $i -ge 0; $i--) {
     $item = $items[$i]
     $itemCurrentF = $itemCurrent.ToString().PadLeft($itemTotal.ToString().Length,"0")
     $dateOccurredF = "{0:MM/dd/yyyy}" -f $item["Date Occurred"]
     Write-Host "- Processing item $itemCurrentF of $($itemTotal) ... " -NoNewline
     If ($item['Date Occurred'] -lt $cutoffDate) {
       $item.Delete()
       Write-Host "Deleted - $dateOccurredF <= $cutoffDateF"
       $itemsDeleted++
     }
     Else {
       Write-Host "Ignored - $dateOccurredF => $cutoffDateF"
     }
     $itemCurrent++
   }
     
   $timeFinished = Get-Date
   $timeDuration = ("{0:hh\:mm\:ss}" -f ($timeFinished - $timeStarted))
   If ($timeDuration.Length -gt 8) { $timeDuration = $timeDuration.Substring(0,12) }
   Else { $timeDuration += ".000" }
   $timeTotalSeconds = [Math]::Round(($timeFinished - $timeStarted).TotalSeconds)
   $deletedPerSecond = [Math]::Round($itemsDeleted / $timeTotalSeconds)
   Write-Host
   Write-Host "Batch Started:  $timeStarted"
   Write-Host "Batch Finished: $timeFinished"
   Write-Host "Batch Duration: $timeDuration"
   Write-Host
   Write-Host "Total Seconds:  $timeTotalSeconds"
   Write-Host "Items Deleted:  $itemsDeleted"
   Write-Host "Deleted/Second: $deletedPerSecond"
   Write-Host
 } UNTIL ($itemsDeleted -le 0)
     
 $web.dispose()


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks a bunch for your response. What are your thoughts on workflow history is it best to just purge the list after a certain time or keep creating new workflow history list after each threshold is met?

0 Votes 0 ·

@Dez-4361
I prefer to purge the workflow history list after a certain time.


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




0 Votes 0 ·

Thanks a bunch for the info and script!

0 Votes 0 ·
sharatha avatar image
0 Votes"
sharatha answered sharatha commented

Just change the Workflow History List to a New History List for the Existing workflow List, in that way All the currently running instance will use the Workflow History List and newly created instances will goes to New History List which is going to be your New Workflow History List. you can do this via SharePoint Designer, below article will help you to create a workflow history list.

https://www.spguides.com/sharepoint-online-workflow-history-list/

Thanks & Regards,

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks so much for response. So this will have no affect at all on all the entries before the new history list creation? Thanks again!

0 Votes 0 ·

There shouldn't be any problem, I did for few of my workflows by creating a new workflow history list and all of them are running just fine as of now.

Thanks & Regards,

0 Votes 0 ·

Thanks for response, do you normally totally remove the old workflow history list or let them stay forever? Just trying to totally understand if there is any real reason to keep the older lists around

0 Votes 0 ·
Show more comments