How to avoid nested If conditions

  • 3 February 2017
  • 2 replies
  • 6 views

Badge +3

Hi, I am still learning K2, I would ideally like to nest If conditions within a Smart Form. I want to avoid using a workflow.

 

My first If statement is essential - it's validation. If the form passes validation then up to 10 items are executed.

 

Two of which are dependant on there being values in textboxes:

  • A create method which adds a row into the database.
  • An update Active Directory update method.

I don't have any real control over the methods in terms of handling errors, etc, if the textboxes are empty.

 

Consequently the form returns an error if either one is empty. I was wondering what options I have and if there are any tricks to get round this.

 

I tried passing in "ZZZZZZZ" as a username but there is an error because the user doesn't exist. I'm frustrated! Thanks


2 replies

Badge +10

What you are trying to achieve should be performed very easy.

 

First Determine what needs to be validated depending on the Data entered within the Form. Not sure how many scenarios, but what I suggest is to create Unbound Rules that will exectue the Form Validation prior to Submit.

 

So basically you have a Form with Fields when the user click on Submit, what the button is going to do is to evaluate the data entered and depending on which case is evaluating will execute the unbound rule that matches the exact data validation. This will let you perform the validations and actions only on the required conditions.

 

After validation will execute the Create/Update or whaterver you want it to do.

 

Does this make sense ?

 

Hope this helps.

 

Dino.

 

 

Badge +3

Hi Dino, thanks! I've not heard of unbound rules, just had a quick look at them. Basically, the form has basic validation with 3 fields mandatory.

 

If the mandatory fields are populated, I wish to execute 10 different actions. One of which is the UpdateUser method which has a mandatory field (not one of the 3 form mandatory fields). Another action to execute is a Create method which also has a mandatory field (again not one of the 3 form mandatory fields).

 

How would I layer the logic? On the Submit button click event I would need a "If form passes validation" step. Would I then add the 8 steps and create 2 unbound rules for the 2 actions above? Inside each of these new unbound rule actions I could then place an If condition on whether the relevant mandatory field is populated?

 

Is that what you meant?

Reply