« Creating documents in Domino without using a form or an agent | Main| Probably useless - LotusScript toAcronym() »

Parsing formulas on the fly via @Eval and @While

Category show-n-tell thursday
Here's the scenario: configuration documents are used to define content (i.e. selectable values in a drop-down), but that content must be a mixture of statically and dynamically defined information, and how the dynamically defined content is determined needs to be adaptable over time. If you're at R6 or above, this is easy: place any formula that should be evaluated at run-time within wiki-style markup in the configuration data, then parse it using @While and @Eval.

strContent := (reference to configuration data, such as a field on the current document or a DbLookup);
@While( @Contains(strContent;"[formula]");
strLeftOfMarkup := @Left(strContent;"[formula]");
strRightOfMarkup := @Right(strContent;"[/formula]");
strRunTimeFormula := @Right(@Left(strContent;"[/formula]");"[formula]");
strContent := strLeftOfMarkup + @Eval(strRunTimeFormula) + strRightOfMarkup
);
strContent

This could be used, for example, to dynamically specify dynamic information at the top of a web page:

Welcome to the [formula]@DbTitle[/formula] website. You are currently logged in as [formula]@Name([CN];@UserName)[/formula].

Then if you later decide to change what information is displayed or how it is determined (i.e. evaluate a querystring), you can do so simply by updating the configuration data, instead of having to update the application's code.


Comments

Gravatar Image1 - I do something similar for my workflow notification code and my export to excel code. I use place holders that get replaced by data from the document being manipulated. The cool part about doing things like this is that it's very easy to write generic snippets of code that can be used in multiple databases.

Sean---

Contact Me

Hire Me

Elsewhere

What the Quote?

"You'll be just below the Bible Belt. So, anatomically speaking..."

Greg Rotz

"You can't polish a turd."

Michael Nurre

"Okay, now, see, that noise... that's not me."

Julian Robichaux

"Imagine if the election came down to Alaska... they'd be runnin' out of their igloos."

Steven Rodgers

"January is like 5 web years ago."

Bruce Elgort

Apparel

Lotus Rocks

I write the code that makes the young girls cry

Current Terror Alert Level

Assorted Linkage

ClustrMap