Friday, January 27, 2012

Kicking Off a Workflow on an Entire List The Poor Man's Way

I have a list that contains several items in it and I have a really cool SharePoint Designer workflow that modifies the properties of the items (columns, permissions, etc..) when it runs.  However, in SharePoint Designer I only have the options to run the workflow automatically when an item is created or when an item changes.  Did I mention that when I said a few items, I really meant a few hundred items, if not more?  I really don’t want to spend the next 2 days manually kicking off the workflow on each item in my list!
One possible solution is to add a Yes/No column to your list, do not add it to the default view, create a datasheet view of your list with the new column visible, and modify your workflow to reset the value in your new column once the workflow has ran.  Once all of that is in place, go to your new datasheet view, set the value in the first row and copy it on down to the bottom.  Let’s take this step-by-step:
1.       Open your List or Document Library and click the List tab on the ribbon menu.  Click on Create Column.


2.       Give your column a name, something like Run Workflow and choose Yes/No (check box) as the type.  Set the Default value to No and uncheck the Add to default view check box, then click OK.


3.       On the ribbon, click on Create View, Click on Datasheet View, give your view a name like RunWorkflow, under Display make sure that the new column that you created (Run Workflow) and one other, generally I choose the Title field or any other field that is going to show a unique value for the items in the list is selected, then click OK.


4.       Open the site that contains the list in SharePoint Designer, click on Workflows and then the workflow that you want to run.

5.       On the workflow settings page make sure that Start workflow automatically when an item is changed is selected and then choose Edit Workflow.


6.       Click on the screen above the first step of your workflow.  Then in the Insert section of the ribbon click Step to add a new step to your workflow.  You can rename the step so that it does not appear to be out of sequence with the other steps in your workflow.


7.       Click on the Condition button on the ribbon and choose If current item field equals value.


8.       Click on the field link and choose the column that you created in step 2.  Then click on the value link and choose Yes.

9.       Click Action on the ribbon and choose Set Field in Current Item.



10.   Click on the field link and choose the column that you created in step 2 and then click the value link and choose No.  Your step should look like this:


11.   Save and Publish your workflow.

Open your list with the view that you created in step 3.  Go to the Yes/No box on the first item, click on it to set it to Yes and then drag the bottom right corner of the cell to the last row of your list.  This should set all of the check boxes to Yes, kicking off your workflow on each item and thus setting the field back to no (no checkmark).

7 comments:

  1. Excellent work. This worked great for me. I had a list with over 400 items in it and a recent enhancement to the site required a workflow to be run to change a status field from "Active" to "Expired" end the end of the year.

    Without this technique I would have had to go in and kick the workflow off for each of the existing 400 items.

    ReplyDelete
  2. can it be done without changing the "modified by" column?

    ReplyDelete
  3. You could script it through Power Shell using the SystemUpdate method instead of Update. Here is more info on that method: https://msdn.microsoft.com/EN-US/library/ms461526.aspx

    ReplyDelete
  4. I know I am a little late here, but if there something noticeable in the datasheet view that would indicate the WF kicked off. I change my values to yes, but the view just remains with the items checked off and nothing happens!

    ReplyDelete
  5. I have a list with 5000 items. How to run a workflow that move all these items without enter 'manually' yes in the fields? It exists a method to do it automatically, only running a workflow? Tnx

    ReplyDelete
  6. Good post. Is there any way to trigger the workflow at a set time everyday for all the list items? Thanks.

    ReplyDelete