Howto reuse code or logic on a smartform.

  • 8 February 2017
  • 4 replies

I am working on some K2 solutions that rely heavily on SmartForms. When building these forms, I usually find that I need to reuse some parts such as logic. What I do now is that I create a button, and place all of that logic 'behind' that button. Next I hide that button. On the locations that I want to implement that logic, I connect to that hidden button.


Basically, what I need is what is referred to as a function in other languages. What would be the best way to do this in SmartForms.

4 replies

So this is one of the perfect examples where Global Variables, Global Expressions, Global Outobound Rules, and why know Global Code Solutions could be shared among the Views/Forms and reused globally.


Nice thinking... I wanted to have some of those but unfortunatelly does not exist. perhaps could be a good product enahancement.


Now tipically is suggested to create Button Item View with dummy controls for buttons and have all your actions among states, or steps of your process. you can setup some params to initialize and just display the right buttons depending on the initializacion view. this is basically just a place holder for your forms.


Depending on the Form in question you will enable "When a Control View execute and Event" and give the buton the power to do something else.


Hope this helps !!!.

Have you looked at using unbound rules?  It's basically the same as what you are doing without the need to add a button to the form/view.  You simply create a new rule, give it a name, and add your conditions/actions.  No need for a triggering event.

Questiom here is how to reuse the same rule in the different form, just like we do copy-paste in code behind. Is it possible to create a reusable rule, like biding the rule in the button and use that control in different views/forms. Thanks. What is the best practice of externatilzing the rules so that it can be reusable.

create one new view write all business logic here , call this view where you required in your forms