Click here to Skip to main content
15,860,859 members
Articles / Productivity Apps and Services / Sharepoint
Tip/Trick

Run Workflow for All Items of List in SharePoint

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
12 Apr 2021CPOL 4.8K   4  
Run Workflow for All Items of List in SharePoint
In some cases, we need to run workflow all items in List which is very panic work via SharePoint GUI. We must select each list item and run workflow manually which is not effective or feasible in case of too many items in list. Additionally, it is time consuming task to run workflow for each item.

Background

In some scenarios, we might need to develop workflows for existing SharePoint list which has several list items. This happens because of some enhancements or user(s) requirements. Normally, we develop a workflow for lists or libraries, and the workflow can execute manually, and an item is added or update automatically.

Scenario

However, in some cases, we need to run a workflow on all items in List which is very hard work via SharePoint GUI. We must select each list item and run workflow manually which is not effective or feasible in case of too many items in list. Additionally, it is time consuming task to run workflow for each item.

Note: workflow means SharePoint workflow which is developed via SharePoint designer.

Here, I am sharing a small piece of code in PowerShell command through which we can accomplish this requirement but note this will not start instantly those workflows. It can take up-to 5 minutes as it is triggered through SharePoint Timer Service. (use SharePoint PowerShell)

Using the PowerShell Script

PowerShell
$webApp = Get-SPWebApplication "http://sharepointUrl/sites/sitename"    

# URL of the Site    
$web = Get-SPWeb -Identity "http://sharepointUrl/sites/sitename"    
$workflowmanager = $web.Site.WorkFlowManager    

# Name of the list    
$list = $web.Lists["List Name"]    

# Name of the Workflow    
$assocname = $list.WorkflowAssociations.GetAssociationByName("On Item Created","en-US")    
$data = $assocname.AssociationData    
$items = $list.Items    
foreach($item in $items)    
{    
   $workflow = $workflowmanager.StartWorkFlow($item,$assocname,$data,$true)    
}
$workflowmanager.Dispose()    
$web.Dispose()

After running this PowerShell script, the workflow will be triggered for each item in the mentioned list. This small powershell script saves huge time which we do manually to run the workflows.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
-- There are no messages in this forum --