RSS

Category Archives: SmartObjects

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!

 

Automatic process version upgrade

First of all… there are terms and conditions. This won’t work in all cases, and for all intents and purposes it’s a bit of an ugly hack, but there are times when something like this is needed (you have loads of live processes which need a new data field urgently, or a new action needs to be added to an activity to bypass a bug and there are live instances which are not yet in error state, etc).

So here’s one way to do this:

  1. Store a “Version” data field in the workflow and keep the latest version label in the .Net app’s app.config file
  2. Catch all exceptions for setting/reading data fields and executing actions
  3. If you get an exception then get the Version data field from the workflow. If it doesn’t exist, upgrade the workflow. If it’s different to the one in the config file, upgrade the workflow.

Upgrading the workflow:

  1. Use the “Process Data” SmartObject to read all the process level data fields from the old process and create a Dictionary out of it.
  2. Create a new instance of the workflow and send it to a holding activity (just a code event with Sync = False). Use the dictionary to set all the data fields so that they are copied from the old process to the new process.
  3. Use the “Activity Instance” Smartobject to get a full list of all activity names for the old workflow and then use a GOTO to go to the most recent Activity.

Obviously there are loads of cases where this won’t work (for example if a later version deleted an activity or data field) but in our case I’m surprised at how well it works. There are also ways of migrating the workflow history over, but that’s a bit more complicated and probably the subject of another post…

 
Leave a comment

Posted by on July 2, 2013 in SmartObjects

 

Management Tab Missing in Workspace

I recently ran into a problem after an upgrade to 1420 whereby the Management tab was missing from the workspace. I did all the regular checks (license, permissions etc) and no luck. If you ever run into this situation, back up your K2Workspace database and then truncate the ActionPermissions table. This resolved it for me.

Thanks to Tyler Clark from K2 for helping me out with this one.

 
2 Comments

Posted by on January 31, 2012 in SmartObjects

 

Are you getting the most value from K2 blackpearl?

As a BPM architect and business analyst I’m in the fairly unique position of having seen how companies all over the world are using K2 blackpearl. It would be nice to be able to say that they are all going about it the right way, but I find that most companies aren’t. That’s not in any way judging anyone, but in reality the best way of using any techology comes from experience, and in most cases companies don’t have the time (or budget) to spend getting experience and building up the expertise to tackle a workflow project using industry best practices.

This isn’t going to be a K2 blackpearl best practices guide, but here are a few checks and balances to make sure you’re on the right track:

1. Get results fast.

As a rule of thumb I feel that I and my team should be able to deliver a useable, valuable workflow project within 3 months. If it takes longer than that then I have a good look at the project – sometimes it’s a large project and there’s a good reason for a longer timescale – but our rule of thumb is 3 months.

2. Choose the right technology.

Spend the time at the start of the project to choose the right tecchnology to fit around K2. In many cases this is simple – you can safely go straight to Microsoft SQL Server and know you’ve chosen well. The business part is usually simple as well – you’re going to be using .Net. The choice of UI technology, however, is critical. Are you going to use ASP.Net? Forms? InfoPath? SharePoint lists? All have their pros and cons, but if you make the wrong choice here you’re going to pay for it over and over again. This leads me to…

3. Fit the requirements to the tech, not the other way round.

Once you’ve chosen your tech, accept the limitations and live with them. There’s no silver bullet technology to solve all your problems. The first thing you want to do at the start of the project is print out a big sign which says “it is what it is” and hang it on the wall in the meeting room.

The most common time I see people struggling with this is with InfoPath. InfoPath is a great technology for getting results fast. I can get a great looking UI done with back end integration in almost no time at all, especially with SmartObject technology. But it’s not ASP.Net. I’ve seen people take InfoPath so far beyond what it’s meant to do that the result is completely un-useable. But I’ve also seen a company which asked “what is InfoPath good at”, they focused on those areas and the result is probably the most successful K2 project I’ve ever seen.

4. Invest time in the API.

Blackpearl has a great API. It deserves to be treated like any API, i.e. don’t just start coding and hope for the best – dig deep first and then build up a re-useable framework using the API. We do this for every project we do, and now we have a well-written, well-documented re-useable, TESTED, generic K2 framework to pop into any project. And no – our framework isnt’ for sale 🙂

5. Buy K2 skills into your project.

I once worked for a .Net startup in London. The company was started by about 15 consultants from a major consultancy company who thought that they could send their consultants on a 2 week .Net course and then write enterprise software. After a few months they hired me. The first thing I told them to do was to delete everything and start again from scratch. What a way to make friends!

My point here is that there is a very experienced community out there, and it’s worth investing in getting it done right. This is possibly the most important point I can make. Buy in the right skills. You have a number of options:

  1. Hire an architect with K2 experience.
  2. Contact K2 directly and ask them to recommend some help.
  3. Contact a K2 partner.

You don’t need to outsource your whole project. At the very least, if your budget is tight you can buy 2 weeks of time from a recommended K2 partner and get your architecture and design correct from day 1. We do this all the time for people. If you start off in the wrong direction you will pay for it in the long run. Again, and again, and again, and again…

Hope that helps!

 
Leave a comment

Posted by on April 29, 2011 in SmartObjects

 

What do you want to see here?

Whenever I come across something interesting I like to let people know. They say it takes a wise man learn from their mistakes, but I believe the people who really get it right are the people who know how to learn from other peoples’ mistakes. So I used to regularly write up my thoughts and email them to work colleagues. Those emails then because this blog and now I’ve got people from 30 countries reading it. My biggest challenge now is to keep making enough mistakes so that I have something new and interesting to write about 🙂

Anyway, this blog isn’t meant to be a forum – K2 Underground does an excellent job of filling that gap. However, if there’s a topic you’d like to see covered, let me know and I’ll see about writing up something about it…

 
Leave a comment

Posted by on April 22, 2011 in SmartObjects

 

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

 

Yoga?

OK, I know this has absolutely nothing to do with K2 blackpearl but it’s one of my favourite Dilberts ever. Had to share… 🙂

 
Leave a comment

Posted by on April 14, 2011 in SmartObjects

 

K2 and .Net 4

Using K2 in a .Net 4 environment is fairly simple, but there are 2 things you need to do to get it to work.

Edit Config Files
  1. Open K2HostServer.config file and add this to the <appSettings>:
    <add key="netfxversion" value="v4.0.30319" />
  2. Open the K2Server.config file and change the .Net version to read as follows:
    <Framework Version="v4.0.30319" />
  3. Open K2.Setup file and change the .Net version to read as follows:
    <Framework Version="v4.0.30319" />
  4. Restart the service
But if you are using a config file…

This came as a bit of a surprise. If you’re referencing a dll which uses a config file then you need to add a reference to this config file in K2HostServer.config because the dll will be loaded in the K2 services’ context (See this post for more about how to do this). The problem is, however, that as soon as you’re referencing a .Net 4 dll this doesn’t work anymore. After much searching, hacking and frustration I found a workaround. Here’s what you do:

  1. Create a config file in the same folder as K2HostServer.config. Name it K2HostServer.exe.config
  2. Add your config file reference to K2HostServer.exe.config and not K2HostServer.config.

Voila. It works. I raised a ticket for this and it seems this is a .Net bug – read here and here for more info.

Hope that helps!

Update: I have verified my approach with K2 and they have confirmed that this approach is both supported and will be the recommended approach.
Another Update: This will work if you’re referencing dll’s from your processes but not if you’re referencing dll’s from a custom security provider. If you’re referencing dll’s from a security provider, you need to add the config entries in K2HostServer.config, not K2HostServer.exe.config.

 
2 Comments

Posted by on March 23, 2011 in SmartObjects

 

Referenced dll’s and config files

In this post below I spoke about what happens to the dll’s you reference from a K2 process. This gets more complicated if you want to include config files with your referenced dll for 2 reasons:

  1. Even if K2 deploys your dll for you (‘copy local’ is set to true) the config file will not be deployed.
  2. You can manually copy your config file, but it won’t be loaded (and will be deleted whenever the K2 service restarts).

If you want config entries to be read you have to use a more roundabout way of getting them. The simplest way of doing this is to add the config settings into the K2HostServer.config file and then restarting your K2 service. This is risky though because each time you upgrade K2 your changes will disappear (OK not always, but most times). A nice compromise I’ve found is to merge the config files:

  1. Copy your config file (mySettings.config) to K2’s Host Server\Bin folder.
  2. Edit K2HostServer.config so that <appSettings> becomes <appSettings file=”mySettings.config”>
  3. Restart the K2 service
 
Leave a comment

Posted by on March 15, 2011 in SmartObjects

 

Stored Procedures to generate InfoPath rules

In an InfoPath project you need to make a decision about where you’re going to store your data, the most common options being either in the InfoPath form itself as XML fields or externally using SmartBox SmartObjects (see my earlier post for the pros and cons of these options).

Assuming you’ve gone the route of using SmartObjects you’ll soon notice that when you have InfoPath controls bound to the Load SmartObject methods and you want to save them, you need to set up a rule for each SmartObject property to copy that field from the Load datasource to the Save datasource. This can mean a lot of clicking!

If you’re happy with splitting your InfoPath up into source files and editing rules, you can save a lot of clicking. Add this stored procedure to your SmartBox database and run it against your SmartBox SmartObject. The result of the query will be a bunch of InfoPath rules which you can copy and paste into your InfoPath source files, repackage the form and then all your rules are done.

CREATE procedure LoadToSave
@tableName      nvarchar(max)
as
begin
SELECT '<xsf:assignmentAction  targetField="xdXDocument:GetDOM(&quot;' + TABLE_NAME +  '_Save&quot;)/dfs:myFields/dfs:queryFields/tns:ExecuteSmartObjectMethod/tns:ExecuteSmartObjectMethodInput/SmartObjectInput/InputProperties/'  + COLUMN_NAME + '" expression="xdXDocument:GetDOM(&quot;' + TABLE_NAME +  '_Load&quot;)/dfs:myFields/dfs:dataFields/tns:ExecuteSmartObjectMethodResponse/tns:ExecuteSmartObjectMethodResult/SmartObjectReturn/ReturnProperties/'  + COLUMN_NAME + '"></xsf:assignmentAction>'
FROM  INFORMATION_SCHEMA.Columns where TABLE_NAME = @tablename
end
CREATE procedure ClearSaveInputParameters
@tableName      nvarchar(max)
as
begin
SELECT '<xsf:assignmentAction  targetField="xdXDocument:GetDOM(&quot;' + TABLE_NAME +  '_Save&quot;)/dfs:myFields/dfs:queryFields/tns:ExecuteSmartObjectMethod/tns:ExecuteSmartObjectMethodInput/SmartObjectInput/InputProperties/'  + COLUMN_NAME + '"  expression="&quot;&quot;"></xsf:assignmentAction>'
FROM  INFORMATION_SCHEMA.Columns where TABLE_NAME = @tablename
end

 
UPDATE:
People have told me that this post doesn’t make a lot of sense, and yeah… they are right. So here’s what I mean:

K2 lets you integrate SmartObject methods into InfoPath forms (another topic, another post) but the upshot is that each SmartObject method becomes a data source in InfoPath. If you’re using smart box SmartObjects to store your data (like we had to do) then you have to do some magic to make it all work nicely on your form. The main issue you have to get your head around is that the data sources are blissfully unaware of each other – just because your Load and Save datasources are methods from the SmartObjects doesn’t mean they know anything about each other.

The most common task you’ll need to do is display the data in the smart box, allow the user to edit it, and then save the data. However, it’s not as simple as that… in reality you need to do the following:
1. Put some text boxes (or other controls) on your infoPath form
2. Bind the text boxes to the fields of the LOAD data source

Now when you execute the LOAD data source the values in the smart box table will be shown on the form. However, to allow the user to edit the values you’re going to need to add a ‘Save’ button, and on this save button you need to add some rules:
1. Copy EVERY SINGLE FIELD value from the LOAD data source to the input of the SAVE data source
2. Execute the SAVE data source

Now imagine if you have a SmartObject with 50 fields in it (NOT good practice by the way, but we had to). You know how many times you need to click to add 50 rules to copy values across? You don’t? No, neither do I, because I refused to do it. I wrote a SQL script to generate the rules for me.

Basically the SQL above will generate InfoPath rules for you which will copy fields from the load data source to the save data source. It’s not idiot proof, but it works in almost all cases. Once you’ve got your rules, you only need to break the Infopath form up into it’s source files, manually edit the manifest file, insert the rules in the right place, repackage it up and REALLY hope you haven’t messed the whole thing up.

Yes, it’s complicated, and yes, it’s risky, but I’ll give $100 to anyone who creates all 50 rules manually and doesn’t break down crying when the structure of the SmartObject changes and they don’t need to do it all again…

 
Leave a comment

Posted by on January 8, 2011 in InfoPath, SmartObjects