unsung hero: @CheckFormulaSyntax
Category fgoto
It's time for another FGOTO post. Earlier today I had occasion to use an @Function that has been around since version 6 but some of you might not even know exists: @CheckFormulaSyntax. Here's what it does:
One challenge this approach presents, however, is the possibility that Formula entered as data will be syntactically incorrect with no warning of its syntactical errors until some "life or death" document fails to route to the correct destination state. You can mitigate this risk, to some extent, simply by adding the following Input Validation to any field intended to store Formula:
Note the use of @ThisValue and @ThisName to allow the Input Validation to evaluate the value and name, respectively, of the current field, allowing you to use the above Formula without modification in any field.
With this validation in place, if syntactical errors are found (sadly, there is still no reliable way to detect logical errors in advance... but we're working on it), the user populating the Formula field will see something akin to the following:
It's time for another FGOTO post. Earlier today I had occasion to use an @Function that has been around since version 6 but some of you might not even know exists: @CheckFormulaSyntax. Here's what it does:
- You pass it any string that is supposed to be valid Notes Formula but might not be syntactically correct.
- If it is, in fact, valid Formula, the function simply returns "1".
- Otherwise, it returns a list comprised of the following:
- The error message returned by the compiler
- Line where the error occurred
- The error column (number of character spaces from the first character in the line where the error occurred, beginning with 1)
- The error offset (number of character spaces from the first character in the block where the error occurred, beginning with 1)
- The length of the text that caused the error
- The actual text that caused the error
- Evaluating dynamically generated Formula (for example, constructing Formula based on variable data)
- Storing Formula within configuration data to allow runtime evaluation of user/admin-maintained code
One challenge this approach presents, however, is the possibility that Formula entered as data will be syntactically incorrect with no warning of its syntactical errors until some "life or death" document fails to route to the correct destination state. You can mitigate this risk, to some extent, simply by adding the following Input Validation to any field intended to store Formula:
syntaxResult := @CheckFormulaSyntax(@ThisValue);
@If(
@Elements(syntaxResult) > 1;
@Failure(
@Implode(("Field " + @ThisName + " contains an invalid formula") : syntaxResult[1] : syntaxResult[6]; ": ")
);
@Success
)
Note the use of @ThisValue and @ThisName to allow the Input Validation to evaluate the value and name, respectively, of the current field, allowing you to use the above Formula without modification in any field.
With this validation in place, if syntactical errors are found (sadly, there is still no reliable way to detect logical errors in advance... but we're working on it), the user populating the Formula field will see something akin to the following:
Comments
Next step - with XPages - is to be able to evaluate custom @Formula code within a 'running' XPage. The eval() JavaScript function within XPages currently has a lot of bugs, but we're working on getting around some of it, and hoping that IBM/Lotus will do the rest
Posted by John Foldager At 06:36:53 AM On 03/16/2010 | - Website - |
{ Link }
Posted by Ben Poole At 07:53:21 AM On 03/16/2010 | - Website - |
{ Link }
Posted by Nathan T. Freeman At 08:49:07 AM On 03/16/2010 | - Website - |