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.
- 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.
- In K2 Studio, go to the Object Browser
- Click on the Process/Activity Data tab (third one down on the left)
- Right-click on References and click Add.
- Give your Method a meaningful name. It can be the same name as the SmartObject.
- 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.
- 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.
- Add an event onto the K2 Studio canvas. In this case it'll be a document event that updates a document's metadata.
- Advance to the Document Metadata screen
- Select the field you want to update and click Assign
- When the Supply a Value For window opens click the Ellipses (…) to open the Context Browser
- Click the Process/Activity Data tab
- Expand the References section and then expand your SmartObject Reference
- Find the field you want to use and click Add
- Then click Next to finish out the wizard
The SmartObject Method Reference wizard opens. Click Next.
So now you've built the SmartObject Reference - now what?
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.