Validation rule? Every order needs at least 1 pizza...

4
I am working on the Pizza Mario case and I would like to insert a condition that every order has to have at least one Pizza. How should I go about that? Is it a validation rule?
asked
4 answers
6

Yes you can use a business rule for his case.

Do the following:

  • In your module add a business rule, with as input parameter an order object.
  • Add an retrieve action for pizza objects en contrain the retrieve on the input order object, with (for example) the costraint `[module.pizza_order/module.order=$order]`, and check first object only option.
  • Use the List / Aggregate microflow action to count the pizza list. If the list is empty ($count = 0) let your business rule return false, otherwise true.

Now your business rule for checking whether an order has pizza's or not, is ready. To apply the rule to the order do the following:

  • Add an before commit event on the order object (or due to higher performance add a customized save button in the order dataview), and connect a microflow to one of it
  • In the connected microflow add the choice widget, and double click on it.
  • In the opened screen you can select the business rule that you want to execute.

The choice widget returns true of false, and you have to decide what you want to do when false occured. You can for example return false, that results in a role back of the commit action, and no order is commited. But that's up to you, you can also choose for a error message.

As an alternative you can integrate the business rule in the before commit microflow.

answered
5

@ Herbert Vuijk, good answer! However, retrieving first object only is sufficient in order to perform this check.

answered
3

I suggest you make a Microflow that checks if a specific order has at least one Pizza.

Then, you can execute the Microflow before committing an 'Order' object or create a custom 'Save' button that executes this Microflow before you commit the object.

The last option is advised to keep your Metamodel 'clean' and to keep the application performing (the Microflow is only executed at the places you defined instead of every time the object is committed).

answered
3

@ Herbert Vuijk, good answer! However, retrieving first object only is sufficient in order to perform this check.

answered