« 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're giving Mommy a face bath... so now she'll stink like you."

Tim Tripcony

"I've always wanted to say, 'Paris is burning", and have it be true."

Jennifer Holland

"When I tried to log in, the server just said, "Que?""

Steven Rodgers

"You make funny coding noises."

Laura Tripcony

"I'm not going to forget that for the same reason scars don't heal."

Tim Tripcony

Apparel

Lotus Rocks

I write the code that makes the young girls cry

Current Terror Alert Level

Assorted Linkage

ClustrMap