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. 09/04/2018With two big projects on hold, I suddenly find myself very available for new short and long term projects. In twenty five years, I don't think I've ever written an entry like this, but if you need the kind of work I do now would be a great time to get in touch. Both of the big projects I had lined up for late summer and early fall have been placed on hold and will be that way for a while. With the kids now all off at college and careers, I'm open to more travel than such than I have been in decades, but unless something else comes along, I'll be here working on updates to Second Signal and other things that ...... 
  2. 07/13/2018Who is HCL and why is it a good thing that they are now the ones behind Notes and Domino?We need to address some biases here. IBM has made a deal under which the Notes & Domino software and intellectual property is now being developed and maintained by HCL America. HCL America is part of the very large "HCL Technologies" company that has grown from its roots in India to become an 8 Billion Dollar company with a global presence in the IT Industry. You could be excused for initially believing, as many people do when they hear this, that "they've outsourced the code to India where they'll milk it ...... 
  3. 03/21/2018Domino Apps on IOS is a Game Changer. Quit holding back.BOOM. This will be as important for the platform as Traveler. If your company has ditched Notes and Domino, I feel sorry for you. For companies that do use Notes/Domino this is a game changer and Apple should be paying attention. Here's why: There are hundreds of little Notes client applications you'd never spend the time and money to build and deploy for your internal user base on IOS that we use Notes for all the time (those of us still using it). Now, those are suddenly ALL available on the iPad. ...... 
  4. 02/15/2018Andrew’s Proposed Gun Laws 
  5. 05/05/2016Is the growing social-sourced economy the modern back door into socialism? 
  6. 04/20/2016Want to be whitelisted? Here are some sensible rules for web site advertising 
  7. 12/30/2015Fantastic new series on Syfy called “The Expanse” – for people who love traditional science fiction 
  8. 10/20/2015My suggestion is to stay away from PayAnywhere(dot)com  
  9. 08/07/2015Here is one for you VMWARE gurus - particularly if you run ESXi without fancy drive arrays 
  10. 08/06/2015The Killer of Orphans (Orphan Documents) 
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.