5 May 2017: I’ve updated this post for 4.6.10 and above here.
Be it on smartforms or your custom ASP.NET forms, the OpenWorklistItem call will return the following error if the current User did not pass the validation rule on K2 Server:
For the K2 Designer and Admins, it’s a simple fact that the User is not the Destination User of this Activity. To the Users of this System, they will be like “What the heck are you trying to say?!?”. So how can we help the Users to better understand what is going on without calling us every time a cryptic message appears?
Find these cryptic out-of-box messages
These messages are stored as a template in [K2 blackpearl folder]\Host Server\bin\HostServerLogging.config.
In this file, you will find all the message templates used by K2. The first three numbers of the MsgID represents a logical section. So for example, MsgID starting with 244 are relating to security.
Of course, you can just modify this file directly, restart your K2 blackpearl Server services and all messages will be friendlier. But what happens on upgrade? Well, there’s a high chance that it will be replaced by the default copy in the installer, so it will be a hassle to make comparisons and update the entire list every time you upgrade. My take? Don’t touch this file unless you are willing to do all the additional work.
Friendly message via ASP.NET
Once you know the message you are looking out for, the rest will be using your try-catch block to capture the error thrown and look out for the MsgID in your error message body.
WorklistItem item = conn.OpenWorklistItem(sn);
// do something else
Console.Writeline("Sorry, you do not have the rights to work on this task.");
Console.Writeline("Sorry, an error had occurred. Please contact the System Administrator and provide the following message:<br/>" + ex.Message);
Friendly message via K2 smartforms
In smartforms, you will need to make use of the Error Handling condition – Error Occurred and read the message via the System Values > Error node.
- Open your Rule Configuration Wizard.
- Add the Error Occurred condition. This will be executed when an error occurs in this Rule.
- Add the An advanced condition is true condition. This condition should be with Error Occurred to create a AND condition like the following:
- Click on an advance condition link, followed by the Add button to add a new row.
- From the Context Browser, expand System Values > Error. Drag the Error Message node and drop it to the Left column text box. Select Contains for the Operator and fill in the MsgID code you are looking for in the Right column text box. Click OK to save and close the dialog.
- Add your friendly message and any other rules(e.g. disable form, navigate to another form etc).
- Lastly, let’s test and see the result.