RSS

Category Archives: Service brokers

Dynamically Assigning Tasks to SharePoint 2013 Users

If you’re using the web designer for a K2 for SharePoint 2013 workflow and you assign a task to a user that someone selects from a people picker then you’ll notice it works pretty seamlessly. However, try do the same thing in K2 Studio and it fails miserably. This is because the value that’s stored for the selected task owner is the SharePoint ID, so if you do assign a task to that user it will be assigned to K2:MyDomain\167

Luckily there’s a way past this, but it’s not obvious. Thanks to Igor from K2 for helping me find this…

Step 1: Create a new SmartObject.

There’s a VERY useful service object which K2 include with the product but by default there’s no SmartObject available over it. We’re going to fix that by creating a new SmartObject for it. Run the SmartObject Testing Tool (in the bin folder) and look for this Service Object:

1 - Service Object

Once you’ve clicked “Create SmartObject” you can change the category (I’ll leave it as Default for now) and publish it:

2 - Published

Step 2: Test the new SmartObject

Open the category you published the SmartObject to and execute it. You’ll see pages of new methods available to you. Look for the one called “Get K2 FQN for SharePoint users” and fill in the details you want. The Site URL will be your SharePoint site, the K2 Label will always be “K2”, and in the User ids field you can enter in a semicolon-delimited list of SharePoint IDs. Run the method and AD users pop out the other end:

3 - Execute

That’s it. Hope that helps someone!

 

Error while deploying SmartObjects to different environments

I keep seeing this error pop up in projects so I’ll add it here as a gotcha. Basically you have a fully working project which has been completely tested, and then just when you’re confident that all is working you deploy to the live environment and boom – you get this error:

Error 1 Deploy SmartObjects: Task error: SmartObject Server Exception: Dependancy could not be created: System.Exception: Dependancy could not be created. Parent does not exist in this environment.

This really is no big deal. To understand the error though, you have to understand the relationship between service objects and SmartObjects. SmartObjects can’t exist on their own – they need a service object to live on top of (consume, if you’re going to get picky). When you call a SmartObject method, the SmartObject calls a method in the underlying service object and it’s the service object which interfaces between the K2 world and the real world. You get some inkling of this relationship when you create the SmartObject in the first place – you registered your service object and then created the SmartObject on top of it.

What isn’t immediately obvious is the fact that the link between the SmartObject and the service object is a GUID, not the name of the service object. This GUID is assigned to the service object when you register it, so when you registered your service object on the live server it was assigned a new GUID, so when you tried to deploy the SmartObject the service object it needs (i.e. the parent) isn’t there.

Generally when you deploy a service object for the first time you want to make careful note of the GUID it’s assigned, and include that GUID in your deployment documentation (yes – you SHOULD be writing deployment documents!). Now when you register your service object on a new K2 server, don’t use the default GUID – you should copy and paste the GUID from your deployment document. Now when you deploy your SmartObject it will no longer be an orphan.

 
4 Comments

Posted by on April 20, 2011 in Service brokers, SmartObjects

 

SmartObject Gotcha – Service Methods not refreshing

We recently spent some time tracking down a bug which turned out to be out of date SmartObject methods in our InfoPath form. We had edited our Smartbox methods to add extra service broker calls, for example to save the SmartObject we call the ‘GetCurrentUser’ and ‘GetCurrentDate’ service methods to store the ModifiedBy and ModifiedDate values, then we call the ‘Save’ service method.

Now… if the SmartObject method is integrated with InfoPath and you change the structure of your SmartObject, the service methods are no longer being updated. This means that if you add new fields they won’t appear in the Save method until you edit the SmartObject, delete the call to the Save service method, re-add it, redeploy the SmartObject and then refresh the form.

Just something to keep in mind.