K2 Unbound Rules & Achieving Nested For loop using unbound rules in K2 Smart forms

K2 have introduced a concept called Unbound rules post 4.5 release.

Unbound rules are nothing but a set of rules which are not bound to any control or event. They can be used as a common method which can be called multiple times across different events instead writing them individually in each event.

Also, as you already know that Nested for each looping is not possible in K2 smart forms, we can achieve it using unbound rules.

To-day I would like to explain how we can create unbound rules and use them across multiple events and then I will show you how we can achieve Nested for each loop using them

Let me start with creating an unbound rule and use it across multiple events.


Let’s assume we have a smart form with some controls along with 3 buttons Previous, Save, Next and on each button click we need to validate the form.

For this requirement we will create an unbound rule we use it across all the 3 button clicks.

Let’s Begin

Create a View as shown below

1 View Layout

All the fields here are mandatory for each button click

Now navigate to Rules tab and click on Add Rule and provide a name to unbound rule as you like. Here in my Case it is ValidateView as shown highlighted below

2 Naming Unbound

Now Navigate to Conditions Tab below and select an advanced condition is true and click on Green link to add the Conditions

3 Select AdvCond

Now add the validation Conditions as shown below and click OK to create advanced Condition.

4 Set AdvConds

Now I would like to show a message when any of this validation fails.

So navigate to Actions tab below and select show a message and click configure link and set the details as shown below

5 Show ValidMessage

Added HTML formatting tags, just to make this Validation message pop – up look pretty J

6 Set ValidMessage

Now we need to stop the execution when this validation gets failed, so we need to add one more rule with name Stop rule execution which will be available in Actions tab. You just need to add this as shown below, there is nothing to configure in this rule.

7 Add StopRule

Now the unbound rule is ready and we can start using this anywhere we required.

So let’s start configuring Save Button rule, click Add rule and from Events tab select when a control on the view raises an event and then click select control and then select the button you wish to configure the rules for.

8 Adding SaveBtnRule

Now I will select save button and then move to Actions tab and select Execute another rule and now click the green Configure link and select the unbound rule that you have created above.

9 Button SaveRule

Now after this rule we can add our logic to save the data or anything we want to do, which is explained in below screen shot. The rules that are written under this will be executed only when the above rule which validateView is successful.

10 BtnSave Final

Now as we did for save button we have to configure for other 2 buttons and use the same unbound rules for validating the controls. Once you configure all the rules the designer should look like something like below

11 All Rules

Now Save this view and add this to a form (or you can run it directly too) and test it.

12 Validation Message Fired

When I click on Save button it throws me a validation message as mandatory fields are empty, the same message will be shown when u click on any button if the mandatory fields are empty.

Now let me put some data into fields and click on Save again and see the result in below screen shot.

13 Data Saved Message

As I have entered all mandatory data the save rule executes successfully and shows me a success message.

So this how we can make use of unbound rules as per our requirement and make our code much efficient.

Now achieving Nested For Loop see it here NestedForLoopUsingUnBoundRules

Author: Vijay

I'm a K2 Certified Developer, helping teams to automate, design, develop & maintain business process applications connecting across multiple platforms with multiple technologies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s