How to start SharePoint 2010 workflow from Infopath 2010 code behind

infopathsharepoint-2010sharepoint-workflowworkflow

I have an Infopath 2010 template with 2 buttons: submit and cancel. When the submit button is clicked I the form is saved to a document library in SharePoint 2010 and the corresponding workflow is clicked off. The user can then open the form and cancel the request by clicking on cancel. I would like to start a different workflow when cancel is clicked. Any ideas as to how that could be done?

Thanks

Best Answer

I have not found a method to kick off a workflow specifically from an Infopath form. I did however find a workaround; here's how I set it up:

  1. Added a column to my list/library that will be set to true when the cancel button is selected.
  2. In my infopath form, add my "cancel" button.
  3. Open the control properties for the button, and select the "Rules" action. Close out of the properties dialog.
  4. I added a fomatting rule for the cancel button so it will only display if the first workflow has started. I also disabled all other editing controls as I only wanted the cancel option to be available.
  5. On the Control Tools contextual tab, in the Button group, click Manage Rules.
  6. Add a new Action rule, it should run two actions: first set the value of the column we created in the first step to true; second submit data using the main data connection.
  7. The workflow you want to run when it is cancelled should be set to run on change. As a first step, evaluate the column created above, and if true, continue the worflow. Make sure you set the value back to false so the workflow doesn't run unintentionally.

Hope that helps.