With a iifformula this you can specify that a variable has to have a specific condition, followed by the specification what happens if the condition is met, otherwise what happens if the condition isn’t met. In this lesson we’re going to dive deeper into the iifformula and how to implement this in a more complex way into your Configuration Model.
iifformula
Context
You sell different Boat models. One of those is the Maria Model tugboat. The Second step of the tugboat Configuration is to decide what size the ships deck should have. But with every model, comes a default value.
Every model has a default starting WIDTH:

Model 1  2m

Model 2  4m

Model 3  5m
We're going to set a default value on the WIDTH feature that is determined by the chosen model. We're going to do this with a iifformula. An iifformula, let you specify what condition has to be met in order to follow a specific action. The iifformula consists of three components:

iif(Condition, result if condition is met, result if condition isn't met)
First thing we're going to do is to add a iifFormula to the WIDTH Feature. You do this by following the steps below:

Open Elfsquad

Go to the Formulas Model

Open the Calculated Value of the WIDTH Feature

Add model 1 as a Variable

Type: iif(
You may notice that after you've typed iif, the formula editor automatically shows you the correct way of adding the iifformula. When this is showed, you can also press the TAB key on your keyboard to autofill the formula.
In the first segment we want to specify the condition that if model 1 is selected the formula has to work. So let's add this to our iifformula:

Add @model1 <> 0 to the formula (We now stated that model 1 has to be selected in order to take effect.)

Add a comma if it is not already there
After the comma we will specify what happens if the condition is met. If Model 1 is selected, we want the Width value to start at 2 meters.

Add a '2' after the comma

Add another comma (If it isn't already there)
Now we have to specify the condition if model 1 is not selected. For now we want it to have no specific starting value. So we add a zero to the formula. Don’t forget to add a close parenthesis at the end.
The formula is now complete and should look like this: iif(@model1<>0,2,0).
Iifformula in an iifformula.
The basics of our Formula have been added to the WIDTH Feature. But this formula only works for Model 1. So we're going to add another part to the iifformula.
It is possible to add another iifformula into another iifformula. In our context, we need to add this to create a calculated starting value, based on the choice of Model for the tugboat.

Open the Formulas Model

Open the Calculated Value of the WIDTH Feature

Click on the pencil to edit the existing iifformula

Add model 2 and 3 to the variables
We are going to make some changes to the existing iifformula. We are going to add a iifformula to the last component of the formula. With this example, we will specify that: If Model 1 is active, the value of WIDTH is 2m. If that is not the case, the formula will check if Model 2 is active and if that is not the case, if Model 3 is active.
You may see that the new iifformula will take over the place of the 0 in the formula. So if Model 1 is not active, the result if condition isn't met section will be activated. This is visualized in the following diagram:
As you can see in the diagram above, we are adding the additional iifformula to the result if condition isn't met part of the formula.
To add an additional iifformula to a iifformula, follow the steps below:

Remove the 0 from the iif(@model1<>0,2,0) formula.

On that position, add another iifformula

add: @model2<>0 to the model

Add a comma (If not already there)

Add the result if met value for model 2 (in this case 4)

Add another comma
Your formula should look like this:

iif(@model1<>0,2,iif(@model2<>0,4, ) )
Next, we are adding another iifformula for model 3. You can do this by repeating the above steps but instead of @model2 you use @model3. The starting value of the WIDTH in combination with model 3 should be 5.
Your formula should look like this:

iif(@model1<>0,2,iif(@model2<>0,4, iif(@model3<>0,5,0)))
In this situation, we add a 0 to the end of the formula to be sure the formula works. If none of the conditions is met, the WIDTH will go back to its own original starting value. Be sure to always close off every iifformula with a closing parenthesis at the end. If you don’t do this, the formula wouldn’t work.
Kommentare
0 Kommentare
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.