Executing Multiple Statements in Formula

I am trying to display a number of icons within a column in a view based on the form the record was made from. So for example:

@If(form = “Form Name1”; 9; 0);

@If(form = “Form Name2”; 12; 0);

@If(form = “Form Name3”; 77; 0);

@If(form = “Form Name4”; 64; 0);

@If(form = “Form Name5”; 147; 0);

@If(form = “Form Name6”; 21; 0);

The column shows up empty when all the statements above are listed. When only two are listed the column displays the value of the second line, completely ignoring any code for the icon listed in the first line of logic.

Been searching the forums for several hours with no @success to date.

What is the proper way to list these statements so that are all evaluated and displayed correctly?

Subject: Executing Multiple Statements in Formula

I think it should be a single @If statement like this:

@If(

form = “Form Name1”; 9;

form = “Form Name2”; 12;

form = “Form Name3”; 77;

form = “Form Name4”; 64;

form = “Form Name5”; 147

form = “Form Name6”; 21;

0);

Subject: RE: Executing Multiple Statements in Formula

Thanks, that fixed it.

Is their a better way to execute this kind of statement or is @if ok?

How come it cannot be just:

form = “Outage”; 9;

form = “Training”; 12;

form = “Project”; 77;

form = “Scheduling”; 64;

form = “Weather”; 147;

form = “Application”; 21;

Can you explain how formula understands all the conditions without an | or an “and” linking them…and @If knows to look for the zero at the end?

Subject: RE: Executing Multiple Statements in Formula

@if is fine.

The syntax of @if is

@if(case1; then1; case2; then2; case3; then3, … caseN; thenN; otherwise);

To make it easier to read we don’t write that all on one line normal. Hope this helps you understand:

@If(

form = “Form Name1”; 9;

form = “Form Name2”; 12;

form = “Form Name3”; 77;

form = “Form Name4”; 64;

form = “Form Name5”; 147

form = “Form Name6”; 21;

0);

Therefore it checks if form= any of the cases and if no match is found it returns 0.

The reason why it cannot be just be:

form = “Form Name1”; 9;

form = “Form Name2”; 12;

form = “Form Name3”; 77;

form = “Form Name4”; 64;

form = “Form Name5”; 147

form = “Form Name6”; 21;

Is that syntax wise that is just a series of instructions:

does form = “Form Name1” - it will return True or False

then 9;

then does form=“Form Name2” - return True or False

then 12

then does form=“Form Name3” - return True or False

then 77;

To the interpreter it looks like you’re just returning a bunch of value which mean nothing.

It’s like I said to you: 1; 9; 0; 12; 0; 77; …

Which doesn’t mean a whole lot. You just want the system to return a single value depending upon the form name.

Subject: RE: Executing Multiple Statements in Formula

THANK YOU!!! Both to Brian and Stephen. This has helped me tremendously. I have a form with a field that has a formula like this:

@if(Condition 1 ; action 1 ;

@if(Condition 2 ; Action 2 ;

@if(Condition 3: Action 3:

“” ) ) )

As more conditions got added, it become a nightmare to maintain. Brian’s example and Stephen’s explanation helped me a great deal.

Thank you both!!!

Subject: RE: Executing Multiple Statements in Formula

But remember that Notes imposes a very strict limit on @Ifs: You can have no more than 99 conditions and 99 actions. :stuck_out_tongue: :wink:

Subject: RE: Executing Multiple Statements in Formula

Thanks for the excellent explanation. The updated logic is working great. Interesting to note the 99 conditions and 99 actions limit. Guess the best thing to do at that point would be to just make a new @If statement. Correct?

Subject: RE: Executing Multiple Statements in Formula

Nope. If you’ve got > 99 conditions to test, this is way past the point where it’s too complex a formula for use in a view, for performance reasons. I suggest you write your formula in a computed field on the form; that will let you store information somewhere, say in a profile document, to relate the original values to the new values, and use that in your much shorter formula.

Subject: RE: Executing Multiple Statements in Formula

What Andre said, plus: if you need to check more than 99 conditions, the chances are pretty good that you ought to be rethinking the logic of the entire formula. You can do individual tests of different “components” of a complex test, you can test against a list of values when several different tests would result in the same return, you can nest @If statements, and so on. I can only remember going past condition #10 once, and that turned out to be something I could rewrite to four single-condition tests after a good night’s sleep.

Subject: RE: Executing Multiple Statements in Formula

RE:

. . @if(Condition 1 ; action 1 ;

. . . . @if(Condition 2 ; Action 2 ;

. . . . . . @if(Condition 3: Action 3:

. . . . . . . .“” ) ) )

As more conditions got added, it become a nightmare to maintain. Brian’s example and Stephen’s explanation helped me a great deal.

With Nested IFs you need to be careful, with what you wrote above you don’t really need nested ifs as it says:

if Condition1 then Action1

else if Condition2 then Action2

. . . . else if Condition3 then Action3

. . . . . . . . else nothing

which could have been written in one if statement.

HOWEVER if the code had been like this:

@if(Condition 1 ;

. . @if(Condition 2 ;

. . . . @if(Condition 3: Action 3; “”);

. . . . Action2 );

. . Action1 )

Then that code looks like

if Condition1 then

. . if Condition2 then

. . . . if Condition3 then Action 3

. . . . else Nothing

. . else Action2

else Action1

That’s why you want to spend a bit of time to make sure you have a “style” when coding to help make it readible and help you maintain the code.

I personally use tab to try and line things up so you might use the following formatting:

Simple Case:

@if( Condition1;

TrueCase;

ElseCase

)

getting into nested IFs you get:

@if(Condition1;

@if(ConditionA:

TrueCase for ConditionA;

ElseCase for ConditionA

);

Condition2;

TrueCase for Condition2;

Condition3;

TrueCase for Condition3;

Otherwise

)

I like to use tab as I find spacing may not be prounced enough when dealing with a lot of nested ifs.

Of course the other problems is if you have a lot of nested ifs you may start wrapping around depending upon how complex your conidtions are. This is why I tend to tab in front of my condition so I can line things up if there are

multiple parts to the condition

@if(@Left(@Uppercase(LongVariableName);1) = “Y” &

@Elements(AnotherVariable) > 0 &

@IsMember(“Apples”;Fruit);

TrueCase;

FalseCase

)

Of course this is not a hard and fast rule, if it’s a simple if I often just write it on one line.