Friday, November 30, 2012

Create a Better SharePoint Survey with K2 Blackpearl

In this blog post, I'm going to show you how to build a survey using K2 Blackpearl and two SharePoint lists.

Candidly, I'll be the first to tell you that the SharePoint Survey template is far my favorite template. Sadly, it looks like the survey remains unchanged in SP 2013 as it still has the look and feel of MOSS. While the survey does offer the convenience of branching logic, I have found that the reporting limitations stymie long-term use of a survey. A requirement came up where a client wanted to have a standard survey to be used quarterly and the ability slice and dice the responses for reporting. This calls for using a single SharePoint list as the survey form and via the magic of K2, we'll capture every response and pair the question with the answer in another list.

This approach works well as you can update the survey form as much or as little as you like and not worry about impacting existing data as the answers are stored in their own repository.

Requirements:

  • K2 Studio
  • Two SharePoint Lists
    • Survey (Note: Not a survey list, but a custom list named 'Survey')
      • List contains several multiple line of text fields where the column name is the question and the field is where users can respond to the question
        • For Example: 1. What did you like about this past quarter?
      • Has a choice field called Status with the options "In Progress" and "Ready to Submit"
        • We'll use this is a line rule to start the workflow
    • QA Pair
      • Custom list with the following columns:
        • Question - Single line of Text
        • Answer - Multiple lines of Text
          • Note: Be sure the type of multiple line of text field (plain, rich, enhanced) matches the type in the Survey list or else you'll have DIV tags all over the place.
        • Survey Form - Lookup
          • Here's how this is configured
            • Gets Information from: Survey
            • In this column: Title
        • Title - Single line of Text

Ready to start surveying the masses? Great!

Now we're going to build a process in K2 Studio that when a user sets the survey status to Ready to Submit, it'll create a pair of the question and answer. This allows users to work on a survey and come back and finish it when their schedule permits.

  1. In K2 Studio, go to process wizards and drag SharePoint Events Process onto the canvas
    • We're going to map the Survey list's fields to a Process level XML. Select Events for List and Library Items.
  2. When prompted, supply the name of the Survey list
  3. At the events selection screen select Item Added and Item Updated
  4. At the metadata mapping screen, click the drop down next to Assign and select All columns to new Process XML Field

  5. Name the XML Field something meaningful like SurveyItem
  6. Click Finish and exit the wizard
  7. These XML fields allow us to access not only the Title for the question, but its contents too.

  8. Drag a SharePoint List Item event onto the canvas
  9. Run the wizard in advanced mode. This will allow us to have one event create as many QA Pairs as we have questions.
    • This isn't required. You can use a List Item event per question if you'd like. It's personal preference on how clean you like your processes.
  10. At the Create List Items click Add
  11. Populate the List Name with QA Pair
  12. At the List Item Metadata screen, click on the Question field and click the drop-down for Assign and select Specific value for selected column. We want this to be the question's text, not the user's response. When asked to supply a value, open up the Context Browser and go to Process/Activity Data>XML Fields>ProcessName>SurveyItem>Metadata>Items>Item. 
    • Find the XML node for the first question and expand it
    • Add the Title field
      • The Name field would just give you the name of the XML Mapping for the field and we don't need that.
    • If I lost you with that prolix XML path, here's a screenshot to help you out.
  13. Repeat step 11 for the Title field in the QA Pair list.
  14. In the Answer field, follow the same step 10 except instead of adding the Title field, select the whole node to give you the full response.

  15. Now let's map the XML for the Survey Form field. Since this is a lookup all you need to add to the Survey Form field is the ID mapped in step 4.
  16. Last but not least, we need to add a line to the activity and set up a line rule so the workflow will only run when the survey is ready to be submitted. Drag a line from Start to your activity, then modify the line's properties. It should look something like this.

Congratulations! You have now created a QA Pair. All you'll have to do is follow steps 9-14 for each additional question in your Survey list. You may want to put another choice in the Status field to prevent people from editing an already submitted survey and resubmitting it to the QA Pair list. This would be done with a line rule and a SharePoint item event that changes the Survey's status to "Submitted."

Ok let's think future state: you add a new column in your Survey and need to add it to the QA Pair list. The best is is to update the XML mapping in the Process/Activity data; delete the field mapped to your SharePoint event (i.e. SurveyItem). When done with that, open up your SharePoint Event Wizard (via the K2 Studio ribbon Process>Integration>SharePoint Events). Following Step 4, create the XML field and give it the exact same name as before and you won't have to worry about gutting and building your Survey from scratch.