0

We installed Sharpeoint 2010 SP2 and then suddently all workflows stopped working, they are all in start mode.

According to this thread, it should be fixed with June CU, we installed it, but this didnt fix the issue: http://social.technet.microsoft.com/Forums/sharepoint/en-US/5a6e6e83-b59f-4099-a86f-a07723ff2b98/workflow-stuck-in-starting-state-after-applying-sharepoint-2010-cu-december-2012

Now, we want to try the script approach, but the script provided there seems it will start workflows in all items, I want to start workflow only when the status is starting.

The script I have is like this

#The purpose of this script is to start the SPD workflow with the windows task scheduler for a trigger
#This should avoid the check in-out issue caused by the December 2012 SP CU patch
#This needs to be run on an account with membership in the farm administration group for SharePoint and Shell in SQL
#You can use a find and replace to replace the server and other names with your actual names
#There are no status messages being used since this will be a scheduled task in the Windows task scheduler

#Add SharePoint modules and create variable space
add-pssnapin microsoft.sharepoint.powershell
start-spassignment -global

#Open the web site, list and the workflow
$site=get-spsite https://mysite.com
$web=get-spweb https://mysite.com/myweb/

#Open the %affected% library or list and workflow association

$affected=$web.getlist("Practical Tips")
$manager=$site.workflowmanager
$culture=[system.globalization.cultureinfo]::currentculture
$wfname="News approval workflow"
$association=$affected.workflowassociations.getassociationbyname($wfname,$culture)
$data=$association.associationdata
$wfrunoption=[microsoft.sharepoint.workflow.spworkflowrunoptions]::synchronous

#Start workflow
foreach ($item in $affected.items) {
$site.workflowmanager.startworkflow($item,$association,$data,$wfrunoption)
}
stop-spassignment -global

1 Answer 1

2

The problem area is here

#Start workflow
foreach ($item in $affected.items) {
$site.workflowmanager.startworkflow($item,$association,$data,$wfrunoption)
}

So you need to add something to workout whether the item has already been approved. I am not sure how the workflow is working. Is there a specific field that hosts the approval status? If you doing something like an approved item is a published item then the following will work:-

    #Start workflow
    foreach ($item in $affected.items) {
      if($item.FileLevel -neq [Microsoft.SharePoint.SPFileLevel]::Published)
         $site.workflowmanager.startworkflow($item,$association,$data,$wfrunoption);
      }
    }

Your Answer

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

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