In SharePoint world it's so common to think of a business scenario where we need to assign Dynamic Approvers for a given workflow! There are several ways to target the business need but in this blog post I'm going to walk you through the process of integrating SharePoint with InfoPath forms to assign Dynamic Approvers for a SharePoint workflow. It is going to be a continuation of my SharePoint InfoPath 2010 Cascading Check-boxes or Multiple-Selection List Boxes blog where we retrieved the approvers' names from a SharePoint list depending upon the region selected by a user.

The goal is to let the end users select more than one approver while filling out the InfoPath form and those approvers will be used as the SharePoint Workflow approvers in the order that they were selected. To get started, open the InfoPath form that's been created in SharePoint InfoPath 2010 Cascading Check-boxes or Multiple-Selection List Boxes (which had two fields Region and Approvers) and add a new Text field named WFApprovers as shown below.

Now we have all the controls that we need in the InfoPath form, the next step is going to be creating rules to capture the Approvers selected by end users to set the WFApprovers field value.

So before we go into the details of the rules right click on Approvers field and Copy XPath as shown below and paste it into notepad, we will need this XPath value later as we set up the rules.

Now it's time set those magic rules! Highlight the Approvers field > select Manage Rules from Ribbon (You can also right click Approvers and select Rules) > New Action as shown below.

Then in the Rules pane, go to Run these actions Add > Set a field's value as shown below.

In the Rule details pop up window Select WFApprovers as the field, and for the value paste the following formula

substring-after(eval(eval(XPath of your Approvers field, 'concat(., "; ")'), ".."), ";")

Now in the formula replace the highlighted text in red with the XPath that you've copied previously into notepad as shown below.

Select OK and your Rule Details window should look like the following!

Copy the above formula/value, we will use it to set up one last thing i.e. Default value of WFApprovers field.Right click WFApprovers field and set the Default Value by pasting the above copied formula as shown below. Make sure you select the check box next to "Refresh value when formula is recalculated".

We've completed setting up the rules in InfoPath form. So as the end users select Approvers, the WFApprovers field will be automatically populated in the order that they've selected. If you preview the InfoPath form and select some Approvers, the Workflow Approvers field should be populated as shown below.

For demonstration purposes, I displayed the WFApprovers field in the form, but in real world scenario you can just hide this control and still build the above logic as it is.

Finally we will publish this InfoPath form to SharePoint server by navigating to File > Publish > SharePoint Server. In the Publishing Wizard you can pick and choose the fields that can be made available as columns in SharePoint site. In our scenario we will publish WFApprovers (shown below) as it contains the Approvers selected by end users.

Once you publish the InfoPath form to a SharePoint library, the WFApprovers field will be available in SharePoint site as a column and then we can build a SP workflow to pick the approvers from the published column. Developing a SharePoint Designer Workflow is not the topic of our discussion so I won't dive into details but you can select the approvers of a workflow as shown below:

I hope you had fun following the blog! Feel free to reach out to me if you have any questions/comments.