Controlling the Flow of a Formula

You can use only a couple of methods to control the flow within a formula. Remember that a formula is a lot like a single line of code. You can't pass parameters into or out of a formula. You have no subroutines to which you can pass control. However, you can stop the execution of a formula with @Return() or cause it to continue with @Success . You can also execute a formula sequence with @Do(statement 1; statement 2; ...) . You can combine either or both of these with @If() to provide a flow control of sorts. In the previous document history example, the execution of the formula was stopped using @Return() unless the document was being saved. The code is shown in the following example:

@If(@IsDocBeingSaved ; @Success ; @Return("") ) ;

Sometimes you need to execute two different series of statements depending on a certain condition in the document. To accomplish this, you use @If() combined with @Do() , as in the following example:

@If(cStatus = "Complete"; @Do(@SetField("dComplete"; @Today); @SetField("cCompletedBy"; @Name([Abbreviate]; @UserName))) ; cStatus = "Pending"; @Do(@SetField("dAssigned"; @Today)); "")

To provide a semblance of control logic can be quite a bit of work using nested @If() and @Do() statements. Go slowly and test your logic at each step of the way.

Категории