PermaLink Consistant formulas08/30/2007 11:19 PM
By my watch, in central time, its still thurday, so I'm posting this as SNTT even though theres very little Thursday left.

I sometimes I just fustrated performing the same tasks over and over again inside the domino designer.

Often times this can't be helped, like when you have a whole bunch of rows and each one of them gets a slightly different hide formula, or a separate cell class on each cell in a column or whatever.

I recently ran into a case where I was doing a web survey, with radio buttons that should formatted the same throughout the form, but, "the same" was going to change.

I know that we needed consistent spacing and I was almost positive that domino radio button rendering would not do.


There were several things that I knew up front.

1.   Whatever I put up in phase 1 would be wrong.
2.   The wrong stuff specified by #1 needed to look consistant and when the new stuff comes in (likely several iterations), it also would need to be consistent.
3.   I know up front that I hate, hate, hate going back and pasteing in one field after another.

Which lead me to think about the @eval function.   I've been around for for a while and I've never used it.   I also can't remember seeing anyone else using it, so, I thought I would give it a try.


Long story -> short it worked awsome, I was able to store a "template" for the formula of rendering my HTML then evaluate that over and over.

Well, it accomplished the goal, but, the needs were not very universal and the solution, however cool to me, was not very portable.

Soon thereafter I stumbled upon by very own personal addressbook.   Look at all those phone numbers, some of them clearly were imported from outlook, some of them came from add to local addressbook within some companies domain and all of them, across the board were formatted differenly.

I'm a "data"   guy, I can't help myself from wanting a consistent format.  One thing for sure, is that the moment that I draw a line in the sand and state, "this is my format"  I will meet someone in a new country, and the formatting will need to be updated.   But, since I've done it everywhere, I will need to apply the same fix to all the places that I did previously (and don't forget any)

This seemed to me to be another oportunity for my new friend the @eval function.

I started out putting my formula in a Computed for Display field, I did my testing, it all worked fine, I did some tweeking, etc it was a wonderfull thing.

Then, at the view level I thought about selecting all then hitting my homegrown ToolsRefreshSelectedDocs, toolbar icon, but stopped because that will not work.  (or maybe it will, but, I know that the lotusscript compute with form will not work), so, instead, I created a CFD field that would update a profile document that contains the formula.    Profile documents are always there and rockin fast.

So, heres how I did it.

In every phone field I put this formula in the input translation formula.


@Eval( @GetProfileField( "Input";"PhoneTranslation"))

What that does is gets the string of text from the profile document and treats it like a formula and comes back with a result.

Then at the top of the form, I generated a computed for display field (marked as hidden)  It had this formula.

Translate := @GetProfileField( "Input";"PhoneTranslation");
@If( Translate!="";@Return("Set.AlreadyDone");"");
ProfileValue := "
FieldVal := @ThisValue;
WellFormed := \"{+}+{0-9-}{ }{(}+{0-9}{)}+{0-9-}\";
Extention := \"{ }{e}{ }+{0-9}\";
@If(
 @Matches( FieldVal; WellFormed); @Return(FieldVal);
 @Matches( FieldVal; WellFormed +Extention); @Return(FieldVal);
 \"\");
StripFormat := \"+\":\" \":\"(\":\")\":\".\":\"-\":\" \";
NoFmt := @ReplaceSubstring( FieldVal;StripFormat;\"\");
RTNValue := @If(        
                @Left( NoFmt;1) = \"1\" & @Length( NoFmt) = 11;
                        \"+1 (\" +@Middle( NoFmt;1;3) + \")\" + @Middle( NoFmt;4;3) + \"-\" + @Middle( NoFmt;7;4);
                @Left( NoFmt;1) != \"1\" & @Length( NoFmt) = 10;
                        \"+1 (\" +@Middle( NoFmt;0;3) + \")\" + @Middle( NoFmt;3;3) + \"-\" + @Middle( NoFmt;6;4);
                FieldVal);
@return(RTNValue);
";
@SetProfileField( "Input";"PhoneTranslation";ProfileValue);
Translate := @GetProfileField( "Input";"PhoneTranslation");
@If(
        Translate!="";
                @Return("Set.Success");
                @Return("Set.Failed"))


I've got 12 minutes, so, Im gonna be quick about it.

If there is already a profile document stored in the database, then don't do anything, just exit out with the @return function, if that part of the @if statement is evaluated, nothing else after it, in the formula will be evaluated.

Directly after that I set the value for the ProfileValue field, notice that there is an opening quote on the first line, then that statement goes on until the closing quote & semicolon several lines down.

Thats the part that I expect will need to change later, but, I don't know how.   When it does change it will need to change everywhere.
So, I set the value into the profile field in the next line, directly after that I read it back.

Now, I didn't do any testing here, but, I assumed that "SOMETHING" could go wrong.   I'm not sure what could go wrong in my personal addressbook, but, just in case I check the value, then promptly do nothing with the result of my check.

Wow, and me with 2 minutes to spare.
Comments :v
No comments.
Add Manual Trackback
Please enter the details of the trackback post. Your trackback will not appear on the site until it has been verified. This won't be immediate, as trackbacks are validated on a scheduled basis. Be patient.











Powered By :

BlogSphere

Join The WebLog Revolution at BlogSphere.net

Dwight Pic
Hot Links
These are my heavy hitters
MSDN DHTML Objects
MSDN JScript

Contact Me
Left Block 3
Monthly Archive
Todays Referrers
RSS News Feed RSS Comments Feed Geo URL Blog Admin OpenNTF BlogSphere