Providing a friendly error message for your K2 error

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:

172-OpenWorklistItemError
OpenWorklistItem error

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.

172-HostServerLoggingMsg
The error message for ID 24411

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.

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.

  1. Open your Rule Configuration Wizard.

    172-RuleWizardConfig
    Rule Wizard Configuration
  2. Add the Error Occurred condition. This will be executed when an error occurs in this Rule.

    172-ErrorOccurred
    Error Occurred condition
  3. Add the An advanced condition is true condition. This condition should be with Error Occurred to create a AND condition like the following:

    172-advCond
    An advanced condition is true with Error occurred
  4. Click on an advance condition link, followed by the Add button to add a new row.

    172-NewCondition
    Add a new row of condition
  5. 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.

    172-conditionDone
    Fill in the conditions
  6. Add your friendly message and any other rules(e.g. disable form, navigate to another form etc).

    172-showMessage
    Add a message
  7. Lastly, let’s test and see the result. 172-result

 

Have fun!

 

Leave a Reply

Your email address will not be published. Required fields are marked *