Sunday, October 26, 2008

SPD Workflow: Start a workflow when the value of a certain field changes

A. Introduction A common requirement that I usually encounter is how to make a workflow start ONLY when a certain list item's field changes. Therefore, I decided to write this article to show how this can be achieved using SharePoint Designer and an auxiliary custom list. B. Scenario I have a custom list called Price List. This list contains four columns: - Product ID of type Single line of text - Product Description of type Single line of text - Price of type Currency - Availability of type Choice (Options are: Available, Out Of Stock) I would like to perform some actions (e.g. send a notification to a certain user) whenever the value of the Availability field for any item changes. C. Preparations - Create a new custom list called Aux Price List. - Rename the default Tile column to Product ID. - Create a new column called Availability of type Single line of text. D. Item Creation Workflow I will create a workflow that starts upon item creation. This workflow is responsible for copying the value of the Availability field to the Aux Price List. - Open Microsoft Office SharePoint Designer 2007. - Click File > Open Site. - Enter the URL of the site containing our custom list called Price List. - Now click File > New > Workflow. - On the Define your new workflow page, enter the following data:
  • Name: Backup Availability field
  • Attachment List: Price List
  • Start Options: Automatically start this workflow when a new item is created
- Click Next, in order to start designing the workflow steps. - Enter Copy data as the Step Name. - In the Actions section, select the action Create List Item. - Click the this list link. - Select Aux Price List in the List field. - Click the field Product ID and then click the Modify button. - In the To this value, click fx. For the source select Current Item and for the field select Product ID. - Click OK. - Click the Add button. For Set this field, select Availability. - In the To this value, click fx. For the source select Current Item and for the field select Availability. - Click OK. - Click OK to save and close the Create New List Item window. - Click Finish, in order to save and publish the workflow. E. Item Update Workflow This workflow is the one that performs some business related tasks when the Availability value of an item changes. Thus, this workflow will start only when items are changed. - Open Microsoft Office SharePoint Designer 2007 - Click File > Open Site. - Enter the URL of the site containing our custom list called Price List. - Now click File > New > Workflow. - On the Define your new workflow page, enter the following data:
  • Name: React on Availability Change
  • Attachment List: Price List
  • Start Options: Automatically start this workflow whenever a new item is changed
- Click Next, in order to start designing the workflow steps. - Enter Test the Availability field for change as the Step Name. - In the Conditions section, select Compare Price List field. - Click the field link and select Availability. - Leave the operator as equals. - Click the value link and then click fx. - For the Lookup Details, select... -- Source = Aux Price List -- Field = Availability - For the Find the List Item, select... -- Field = Aux Price List: Product ID -- Value = Click fx. For the source select Current Item and for the field select Product ID. - Click OK to save the lookup. - A warning message gets displayed. Click Yes to continue. - In the Actions section, select the action Stop Workflow. - Click the this message link and type the text: Workflow stopped because the Availability field has not changed. - Click the Add 'Else If' Conditional Branch. - In the Else branch add the action Log to History list. - Click the message link and type the text: The Availability field has changed. - Add the action Update List Item. - Click the this list link. - Select Aux Price List in the List field. - Click the Add button. For Set this field, select Availability. - In the To this value, click fx. For the source select Current Item and for the field select Availability. - Click OK. - In the Find the List Item, select ... -- Field = Aux Price List:Product ID -- Value = Click fx. For the source select Current Item and for the field select Product ID. - Click OK to save and close the Update List Item window. - A warning message gets displayed. Click Yes to continue. - Now you can add further steps for handling the event of changing the Availability field, e.g. Send an Email. - Click Finish, in order to save and publish the workflow. F. Test the solution 1. Create a new item. -- Check that the Backup Availability Field workflow has completed successfully. -- Check that the data of the new item is copied correctly to the Aux Price List. 2. Edit the created item by changing any field other than the Avilability. -- Check that the React on Availability Change workflow has completed successfully. -- Check that the History Log displays the comment: Workflow stopped because the Availability field has not changed. 3. Edit the created item by changing the Availability filed. -- Check that the React on Availability Change workflow has completed successfully. -- Check that the History Log displays the comment: The Availability field has changed. -- Check that the corresponding item in the Aux Price list has been updated correctly. G. Related articles SharePoint Designer Workflows: How to Tell Which Fields Have Changed

5 comments:

maria said...

Resourceful blog and great post about SPD Workflow.
Workflow is an important part of any SharePoint deployment, SharePoint designer has extremely powerful capabilities for developing bespoke workflow.
Thanks.
SharePoint Consulting

RD said...

Hi,

Being able to build my own workflows would greatly improve a Sharepoint list used by some collegues in my departement. I am working in a IT helpdesk. I followed your procedure to "Start a workflow when the value of a certain field changes". I was able to build the workflows without any problem and I even see them when accessing my list setting but the workflows will not run. I have WSS installed on Windows Server 2003 (test environment). Do you have any idea why my workflows will not run?

Richard

Unknown said...

I'm using your technique on my SharePoint 2007 site, but then it occurred to me, what if a user decides to change the Product ID field in Price List? Wouldn't that break this technique?
Is there a way to either:
Keep the Product ID field up to date in Aux Price list,
Or lock the Product ID field so it cannot be modified?

Ramanjulu said...

hi samar,
do you have solution for the same in SP2010. My requirement is same like i want to restart the workflow when item is changed or edited.

Samar Hossam said...

Hi Ramanjulu,

I am sorry for not being able to help, but I haven't worked with SP 2010,

Best regards,
Samar