Wednesday, August 22, 2012

SmartObject References are your new Best Friend

I was recently working on a K2 project where there was an abundance of metadata. In several of my activities I was using SmartObjects to update as few as three fields and as many as a dozen fields. Originally I was building each event by digging through the environment browser and slogging through each event wizard. That means every time I built or modified an event, in the environment browser I'd have to expand SmartObject Server(s)>SmartObject Server>Site Collection>Subsite>List>Method>Field. For those keeping track at home, that's seven levels deep.

While you could restructure the categories for your SmartObjects via the SmartObject Service Tester or deploying them via your K2 Studio project, that approach only takes away two levels and still leaves room for error.

As a proponent of the no-folder movement in SharePoint, I fatigue easily when digging through folder/node structures. That's when I threw my hands up and said "There's got to be a better way!"

Fortunately there is! You can add a SmartObject reference in your process to curtail your development time and leave less room for error in your events.

Here's how:

  1. Identify the SmartObject and the method you want to use. If you're using a non-list method, you'll need to know the input parameter(s). Even if you're using a list method, you'll most likely want an input parameter unless you're all about working with arrays.
  2. In K2 Studio, go to the Object Browser
  3. Click on the Process/Activity Data tab (third one down on the left)
  4. Right-click on References and click Add.
  5. The SmartObject Method Reference wizard opens. Click Next.

  6. Give your Method a meaningful name. It can be the same name as the SmartObject.
  7. In the SmartObject Method field, open the Environment browser and find the method for your SmartObject. Add the method onto the field and click Next. I promise this is the only time you'll have to dig seven layers deep to use this SmartObject.

  8. The Bind Method Input Parameters is where you'll define the inputs that will load the values for the particular item. This will vary by your method so it's up to you as to what to put here. While you can hard-code the input, it's in your best interest to use a data field instead.
  9. So now you've built the SmartObject Reference - now what?

  10. Add an event onto the K2 Studio canvas. In this case it'll be a document event that updates a document's metadata.
  11. Advance to the Document Metadata screen
  12. Select the field you want to update and click Assign
  13. When the Supply a Value For window opens click the Ellipses () to open the Context Browser
  14. Click the Process/Activity Data tab
  15. Expand the References section and then expand your SmartObject Reference
  16. Find the field you want to use and click Add


  17. Then click Next to finish out the wizard

Now that you're done with this event, follow steps 8-15 to add another field from the SmartObject elsewhere in your process.

Wasn't that easy? You can now easily add a SmartObject to your process in an efficient and consistent manner. From the time savings alone, SmartObject references will definitely become your new best friend when developing processes.

And the possibilities with SmartObject References are endless. If you're developing an event driven process that runs in parallel, you can follow this excellent blog post about how to use process activity data as the bind method for your SmartObject Reference. Or if you're running a process as an Interprocess Communication Event, you can use data from the parent process to bind your sub-process' SmartObject References.