Friendly Error Message on K2 smartforms

Friendly Error Message on K2 smartforms

Two years ago, I’ve posted an article on Providing a friendly error message for your K2 error on CodeCodeCode.Ninja. At that time, the version of K2 should be around 4.6.8 to 4.6.9 and the rules configuration in the article works perfectly to intercept a common error like the “Worklist item could not be opened”. Recently, I tested the same rule configuration under K2 4.6.10 and above and found that the method does not work anymore and I will like to show you a new way to show friendly error message on K2 smartforms.

The Previous Method

In the previous method, I used the “If an error occurred” condition in the “When the Form is Initializing” event. This means that the “error catch and handling” works within the event only.

172-showMessage

The New Method

In the new method, I will be using the “When the Form is in Error” event. The good thing about this event is that it allows me to consolidate handling of all errors captured on the form level within this rule and this also shortens the number of lines for the other rules that requires error handling.

Before we start on the detailed guide, I will show you my test form. It will try to run an “Open a Worklist Item” event on the “When the Form is Initializing” rule and shows a popup message when the “When the Form is Initialized” rule executes. This also means that if the “Open a Worklist Item” event fails to complete, the popup message will note appear due to the error.

Here’s how the form looks like when “Open a Worklist Item” event returns an error.

The Test Form
The Test Form

Here’s how the Rule Designer looks like.

The Rule Designer before the change
The Rule Designer before the change

This is the “When the Form is Initializing” rule.

The form initializing rule before the change
The Form Initializing rule before the change

This is the “When the Form is Initialized” rule.

The Form Initialized rule before the change
The Form Initialized rule before the change

So let’s jump into the guide!

Step by step guide to provide a friendly error message on K2 smartforms

So here’s the step by step guide:

  1. On the Form Designer, click on Add Rule to add a new rule.

    Click on Add Rule
    Click on Add Rule
  2. Select “When the Form raises an event” from the Events tab. Set the event type to “In Error”. This event will capture all errors on the form level.

    Event Setup
    Event Setup
  3. In the Conditions tab, select “an advanced condition is true”. Next, click on the “an advanced condition” link to configure the condition.

    Condition set part 1
    Condition set part 1
  4. In the Rule Designer, click on Add to add a new row. Drag and drop Error > Error Message to the Left column, set the Operator to Contains and set the Right column value to 24411. We will capture the “Open a Worklist Item” error, which contains the unique error number “24411”.  You can refer to the error message at the top of this article. Click on OK to complete the setup.

    Condition setup part 2
    Condition setup part 2
  5. We will be providing a friendly error message to inform the user that he/she does not have access to this task. Add a “Show a message” event and click on “configure”.

    Add a message event
    Add a message event
  6. Let’s fill in the friendly message and click OK.

    The friendly message
    The friendly message
  7. Since the user do not have access to the task, let’s navigate the user back to the Home form.

    "Navigate to another Form" event
    “Navigate to another Form” event
  8. Now, this is the important part. This advanced condition will always evaluate to true if there is no Else condition. So let’s add an Else condition.

    Add "Else" condition
    Add “Else” condition
  9. Since there’s no other error I am looking out for, let us make use of the “Continue to next execution” event to complete the “else” condition. Click OK to complete the rule editing.

    "Continue to next execution" event
    “Continue to next execution” event
  10. Now our rules configuration is completed. Click on the save button to save the changes.

    Save the changes
    Save the changes
  11. Lastly, test the form. You will see that the forms now captures any error with “24411” within the error message and displays my friendly message instead. Click on OK and the form will navigate to my Home form as per the configuration.

    Friendly error message on K2 smartforms
    Friendly error message on K2 smartforms

 

That’s the end of my guide on providing a friendly error message on K2 smartforms.

Have fun!

Ji Kai

Ji Kai

Director / Principal Consultant at Alrighty Labs Pte. Ltd.
Ji Kai is the Director and Principal Consultant of Alrighty Labs Pte. Ltd. He has over 10 years of experience in solution designing, consulting and management of software development projects in both private and public sectors. His primary responsibility is to take lead in customer engagements and use his expertise in K2 technologies to assist customers to design successful business process applications. In addition, he has proven past records of leading the successful delivery of complex business process applications on K2 and Microsoft technologies.

Linkedin
Ji Kai

Leave a Reply