Wednesday, November 7, 2012

How to Use a Managed Metadata Value in your K2 Designer Process

What I really like about K2 Designer for SharePoint (K2D4SP) is how easy it is to incorporate columns into your processes. You don't need to worry about mapping XML fields to retrieve column values as they're right at your fingertips. Drag and drop process development is pretty awesome and I believe this accessibility really empowers end users and process owners as they can easily build their existing processes in SharePoint without having to be workflow jedis.

Whether you're a jedi or a padawan, you may run into a sith lord, I mean a limitation if your workflow involves a managed metadata column. Currently, K2D4SP does not expose a managed metadata column to end users. What can you do if you have a rule that you want to route a document based on a value in this column?

I found there's two solutions: one involves a SmartObject event in your K2D4SP process, the other involves an InterProcess Communication event. Both solutions have their merits, so in this post I'll cover both approaches.

SmartObject Event

Using this approach we will perform use a SmartObject method to retrieve our managed metadata value and capture the result in a data field which we can use in our K2D4SP line rules.

Requirements:

  • A SmartObject for the list the process runs on
  • Two data fields: ID and ManagedMetadata

Steps:

  1. In K2 Designer for SharePoint, set a data field of ID and ManagedMetadata
    • If you're working with a library, instead of ID set a data field to Document Name
  2. In your K2D4SP process, add a SmartObject event
  3. Step through the SmartObject wizard and select the SmartObject for this list
  4. Select the Get or Load method.
  5. For the input, supply it so ID in the list equals your data field ID
  6. Map the managed metadata column to the data field ManagedMetadata
  7. Finish the event wizard

You can now build line rules utilizing the data field ManagedMetadata.

InterProcess Communication Event

Using this approach we will build a sub-process which will perform the same event as the SmartObject Event, only in K2 Studio.

Requirements:

  • A data field called ManagedMetadata
  • K2 Studio

Why am I not using SmartObjects with this approach? You very well could use a SmartObject, this is just a different approach but it offers the same outcome as using a SmartObject. If you want to use a SmartObject, use it as the destination rule for the activity, and use a data event instead of a list item event to map the item's values to the data field.

Steps:

  1. In K2 Designer for SharePoint, set a data field of ID and ManagedMetadata
    • If you're working with a library, instead of ID set a data field to Document Name
  2. In your K2D4SP process, set a data event called ManagedMetadata
  3. Add a placeholder event where you want to call the IPC
  4. Open up K2 Studio and create a new process
  5. Create two process level data fields: ItemID and ManagedMetadata
  6. In K2 Studio, Drag a list item event onto the canvas
  7. What this event will do is query the list, specifically the list item, the process is currently running on. We'll map the managed metadata field to a data field and then pass it back to the K2D4SP process.

  8. In the wizard, select Get List Items
  9. Set the event wizard to query the list in question
  10. In the List Item ID field, used the process level data field ItemID
  11. In the wizards List Item Metadata screen, find your managed metadata column and assign the data field ManagedMetadata to the column
  12. Save and deploy the process
  13. Now that your K2 Studio process is built, return to your K2D4SP process and replace the placeholder event with a Call Sub Workflow event.

  14. Select the sub-workflow to call and select wait for sub-workflow to complete
  15. Select your authentication preference
  16. At the send data screen, map ItemID to the SharePoint column ID
  17. At the receive data screen, map the K2 Studio data field ManagedMetadata to the K2D4SP data field ManagedMetadata

You can now save and deploy the process. To validate it works without having to kick off the K2D4SP process, start a new instance of the process from the process portal or K2 Workspace. Be sure to load the data fields, and have it run on a test item.

What's Best for You?

It comes down to your requirements and what needs to be done. If you don't have access to K2 Studio, the SmartObject event is obviously the (only) way to go. What's convenient is if you don't have K2 Studio, you don't need to rely on a developer to build the sub-process - which really empowers the end user.

But if you have access to K2 Studio, I'd recommend utilizing the sub-process. While it does require a little more overhead and means you now have one more process to maintain, I feel it offers the greatest flexibility. The chief reason being that you can build a tertiary workflow in K2 Studio if you need to and perform some additional activities utilizing the value from the managed metadata column. This lends itself to being more efficient than dumping several sub-workflow events in K2D4SP. Plus, if you're going to work with SmartObjects in your process, IMO it is much easier to manage them in K2 Studio than K2D4SP. Here's an earlier blog about why I'm a fan of Smart Objects.

Another reason is if you like raw data, the sub-process can give you all the XML you'll ever want right at your fingertips. And lastly, I feel from a knowledge transfer perspective, if the process owner changes and they're in charge of updating the K2D4SP process, they don't have to teach their replacement about what a SmartObject is and what the get method does. This in turn leaves the K2D4SP process cleaner and therefore easier to maintain for end users.

While this may seem like a lot of overhead to utilize a single field, it is not that bad. But given that managed metadata is here to stay in SharePoint-land, I hope that in a future release K2 will make it easier to work with this powerful column in K2D4SP.