Andrew Pollack's Blog

Technology, Family, Entertainment, Politics, and Random Noise

Domino Technote - Undocumented function plus cool code lets you get the current location name, thus any data from the current location in pure formula language.

By Andrew Pollack on 07/01/2006 at 11:24 PM EDT

I don't post technotes like this often, but rest assured fans of mine, the old man still knows a few things. Someone we all know and love was bouncing a problem off me. He needed to lookup the currently active location document name. @Environment wouldn't work because you can't lookup non-user variables. The tricky part is that it had to be all formula language.

He tipped me to an undocumented function "@LocationGetInfo". After dumping the mail6.ntf and pernames.ntf to dxl, I came up with only a few parameters for that function.

@LocationGetInfo([HomeServer])
@LocationGetInfo([InternetMailAddress])
@LocationGetInfo([NamePreference])
@LocationGetInfo([BookmarksFilename])
@LocationGetInfo([SametimeServer])

None of these did what we wanted. After some hacking and a little educated guesswork, I came up with this one:

@LocationGetInfo([UNID])

That was magic. Once we had that, I quickly wrote this formula to get the name. With the name, you can lookup any field on the document of course.

n := @Text(@LocationGetInfo([UNID]));
locList := @DbColumn("":"NoCache" ; "": "Names.nsf" ; "Locations"; 1);
@For( x := 1 ; x <= @Elements(LocList) ; x := x+1 ;
t := @DbLookup("":""; "":"Names.nsf"; "Locations"; @Subset(@Subset(loclist; x) ; -1) ; "Name" ; [ReturnDocumentUniqueID]);
@If(n = @Text(t) ; @Do(@Set("LocationName"; @Subset(@Subset(loclist; x) ; -1) ); x := @Elements(loclist) + 1 ) ; "")
);
@Prompt([Ok];"";LocationName)

Looking at this, the first line gets the unid of the current location. Next, we get a list of all the locations. Then we lookup each location in order and check the unid. When we have a match, we set the value of the name to our internal variable "locationName" and then also set x to larger than the list of locations so we don't do any more lookups than we have to.


There are  - loading -  comments....

My own thoughts on this are...By Rock on 07/01/2006 at 11:46 PM EDT
Hey, I'm the guy who asked Andrew for the brainstorming on this :)

And of course, I had to see if I could "one plus" his brilliant formula - so I
did, using @Transform:

n := @Text(@LocationGetInfo([UNID]));
loclist := @DbColumn("" : ""; "" : "Names.nsf"; "Locations"; 1);
location := @Trim(@Transform(loclist; "curloc"; @If(n = @Text(@DbLookup("":"";
"":"Names.nsf"; "Locations"; curloc ; 1 ; [ReturnDocumentUniqueID])); curloc;
"")));
@Prompt([Ok];"";location)

Basically the logic is the same, just less code. It does the lookup like
before, but if it doesn't match it makes it an empty string; if it matches, it
returns the location name. Then the resulting list is trimmed to remove the
spaces.

GREAT stuff, Andrew - thanks for the help :)

--Rock
Rock's code only LOOKS better....By Andrew Pollack on 07/02/2006 at 08:55 AM EDT


If you compare these, Rock's code doesn't exit after finding the location, so
it does a lookup for every doc in the view, not just the ones until it finds
the right location document. It also assigns a value to a string list for
every lookup, then at the end compares each value to see if its a null string
when it does the @Trim()

I'll stick with mine, Rock. Thanks!
Why not just use @GetDocField( documentUNID ; fieldName ) ?By Craig Wiseman on 07/03/2006 at 08:32 AM EDT
Since you get the UNID, why not just use:

@GetDocField( documentUNID ; "Name" ) to get the name and any other desired
fields?
Not that I can test this, b/c:By Craig Wiseman on 07/03/2006 at 08:45 AM EDT
Whenever I try to run
n := @Text(@LocationGetInfo([UNID]));

I get a "Document not found" dialog. Notes Client 7.0.1 on WinXPsp2.
Interesting. It must be a matter of context.By Andrew Pollack on 07/03/2006 at 09:55 AM EDT
I'm using 7.0.1 and no problem. The button is in the rich text field of an open
mail document. Perhaps you have to save the document first, or must have a
currently selected document.
Ran ncompact -c -i on my names.nsf and it works now...By Craig Wiseman on 07/03/2006 at 05:39 PM EDT
@GetDocField only works in the current database. Location is in local directory.By Andrew Pollack on 07/03/2006 at 09:54 AM EDT
Your location document is in the local names.nsf file, where this button or
formula may very well be located in a database other than that.

You can use @GetDocField if you first do @Command([FileOpenDatabase]...) then
@UpdateformulaContext but then you've actually opened the other file -- visibly
- and you have to do @Command([fileclosewindow]) followed by
@UpdateformulaContext to continue -- and if there is any problem along the way,
you're closing the wrong window.

UGLY.
duh....By Craig Wiseman on 07/03/2006 at 03:55 PM EDT
I knew that, not that I let my brain interfer with my typing.
I'm still working out why
@LocationGetInfo([UNID])
won't work for me.

I have a simple 'code store' database. I have a saved document with a a button
with just

n := @Text(@LocationGetInfo([UNID]));
@Prompt([Ok];"n ";n )

in it. Doesn't work.

I just put the button in an email, doesn't work. I've got something mangled
somewhere.

Use @LocationGetInfo([FullName]) By Jens Winkelmann on 08/18/2006 at 08:19 AM EDT
You can use this @Function @LocationGetInfo([FullName])
Fantastic!By Andrew Pollack on 08/18/2006 at 08:57 AM EDT
I've tested it, it works. It will become a blog entry.
re: Use @LocationGetInfo([FullName]) By Wolfgang Hass on 05/25/2009 at 10:01 AM EDT
Great, I love it. Never would have tested that... FullName is associated with
other stuff. But it works!!!!
Too bad LotusScript is out and reading system environment variablesBy Lars Berntrop-Bos on 08/22/2006 at 04:51 AM EDT
Using LS you can do:
Private Sub update_current_location
Dim ses As New NotesSession
Dim v As Variant
EnvLocation = ses.GetEnvironmentString(ENV_LOCATION, True)
v = Split(EnvLocation, LOCATION_DELIM)
currentLocation = v(0)
End Sub ' update_current_location

I use this in app initialization and SetEnv a user notes.ini var with it so we
can use it in formulalanguage.


Other Recent Stories...

  1. 03/26/2019Undestanding how OAUTH scopes will bring the concept of APPS to your Domino serverWhile a full description of OATH is way beyond what I can do in this quick blog entry, I wanted to talk a bit about how "SCOPES" interact with the already rich authorization model used by Domino. Thanks to the fantastic work by John Curtis and his team, the node.js integration with Domino is going to be getting a rich security model. What we know is that a user's authorizations will be respected through the node.js application to the Domino server -- including reader names, ACLs, Roles, and so on. The way ...... 
  2. 02/05/2019Toro Yard Equipment - Not really a premium brand as far as I am concernedDear Toro Customer Service, I arm writing about the following machine: Toro Power Max 1120 OXEModel:38654S/N:31000#### Specifically, bearing part #:63-3450 This is the part ($15 online / $25 at the local dealer) that caused me to raise my objections on-line. This piece of garbage is supposed to be a bearing. It carries the shaft which drives both stages of the auger. The shaft passes through the bearing (which is what bearings do) after the auger drive pulley as the shaft goes through the back (engine ...... 
  3. 10/08/2018Will you be at the NYC Launch Event for HCL Domino v10 -- Find me!Come find me in NYC on Wednesday at the Launch Event if you're there. I really do want to talk to ...... 
  4. 09/04/2018With two big projects on hold, I suddenly find myself very available for new short and long term projects.  
  5. 07/13/2018Who is HCL and why is it a good thing that they are now the ones behind Notes and Domino? 
  6. 03/21/2018Domino Apps on IOS is a Game Changer. Quit holding back. 
  7. 02/15/2018Andrew’s Proposed Gun Laws 
  8. 05/05/2016Is the growing social-sourced economy the modern back door into socialism? 
  9. 04/20/2016Want to be whitelisted? Here are some sensible rules for web site advertising 
  10. 12/30/2015Fantastic new series on Syfy called “The Expanse” – for people who love traditional science fiction 
Click here for more articles.....


pen icon Comment Entry
Subject
Your Name
Homepage
*Your Email
* Your email address is required, but not displayed.
 
Your thoughts....
 
Remember Me  

Please wait while your document is saved.