In this post, I am going to show you how you can execute out of the box SharePoint 2010 approval workflow with dynamic approvers.
Let’s say, you have a list on which you have Approval workflow configured and you want the approver to be picked from the Person or Group type field from within the list.
Let’s assume , the ID is being specified in the query string of the page such as
StartWorfklow.aspx?ItemID=5
I will be making use of Jquery and SPServices from codeplex for this purpose.
First of all, we will retrieve the our specified item from this list and then retrieve the value of this Person or Group field.
When we retrieve the person or group field from the web services, it is returned as 1;#Madhur Ahuja. Where 1 is the ID of the row in User Information List and Madhur Ahuja is the display name.
To pass it to Approval Workflow, we need the login name.
We will query the User Information List to obtain the login name.
We get the login name in the variable ows_Name. Now we can fire the Approval workflow passing it the login name.
Note the templateId below, its the GUID of the SharePoint 2010 Approval workflow which is associated with the list.
Here, the key is the variable assocData, which is nothing but the Association Data of the workflow. In SharePoint 2010 Approval workflow, its the serialized XML of the infopath form. This variable is defnied as the XML string as below:
The full code can be downloaded from my gist here.