API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Computing WebDbName on the Server
The other day I was writing an agent that was running on a schedule. It needed to update a document in another database. One of the things it needed to update was the path to the other database. Luckily, the Evaluate macro helped me out.

The document I was updating was a profile document in the other database (not the one where the agent was running). One field on the profile is a path to the database - in the form of "http://server_host_name/" + @WebDbName. I couldn't use a computed field with "compute with form" because the server host name couldn't be looked up. In my script I would compute the host name (I had a hard-coded table of servers and hosts names) inside the script and then set the field value. How did I do the @WebDbName part since my agent was running in another database?

Well, there's a couple ways to do this. One, I could have had a computed (or computed for display) field on the destination profile that computes just @WebDbName. Then my agent would do a "compute with form" on the destination profile and read the value that was computed. But I personally like my other method:

I tried, on a whim, to use the Evaluate statement in LotusScript to compute the formula in the context of the destination profile. That last part is the key (that's why I emphasized it). When you use the second parameter in the Evaluate statement, it uses that document as it's source. Normally you only need that if you're grabbing fields off that second document. But in my case I was using it for context:

Evaluate("@WebDbName", destProfile)

So the formula runs in the context of the destination profile (which means it runs in the destination database) and returns the web path to that destination database. Nice, huh?