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.
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.
Here’s how the Rule Designer looks like.
This is the “When the Form is Initializing” rule.
This is the “When the Form is Initialized” rule.
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:
- On the Form Designer, click on Add Rule to add a new rule.
- 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.
- In the Conditions tab, select “an advanced condition is true”. Next, click on the “an advanced condition” link to configure the condition.
- 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.
- 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”.
- Let’s fill in the friendly message and click OK.
- Since the user do not have access to the task, let’s navigate the user back to the Home form.
- 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.
- 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.
- Now our rules configuration is completed. Click on the save button to save the changes.
- 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.
That’s the end of my guide on providing a friendly error message on K2 smartforms.
Latest posts by Ji Kai (see all)
- Multiple records inserted with RuntimeListViewRowCount option - 30 May 2017
- Friendly Error Message on K2 smartforms - 04 May 2017
- Add company logo and change K2 login form descriptions - 02 Aug 2016