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. 05/05/2016Is the growing social-sourced economy the modern back door into socialism?Is the growing social-sourced economy the modern back door into socialism? I read a really insightful post a couple of days ago that suggested the use of social network funding sites like “Go Fund Me” and “Kickstarter” have come about and gained popularity in part because the existing economy in no longer serving its purpose for anyone who isn’t already wealthy. Have the traditional ways to get new ventures funded become closed to all but a few who aren’t already connected to them and so onerous as to make ...... 
  2. 04/20/2016Want to be whitelisted? Here are some sensible rules for web site advertisingAn increasing number of websites are now detecting when users have ad-blocking enabled, and refuse to show content unless you "whitelist" their site (disable your ad-blocking for them). I think that is a fair decision on their part, it's how they pay for the site. However, if you want me (and many others) to white list your site, there are some rules you should follow. If you violate these rules, I won't whitelist your site, I'll just find content elsewhere. 1. The total space taken up by advertisements ...... 
  3. 12/30/2015Fantastic new series on Syfy called “The Expanse” – for people who love traditional science fiction[] “The Expanse” is a new science fiction series being broadcast onthe Syfy channelthis winter. It’s closely based on a series of books by author James S. A. Corey beginning with “Leviathan Wakes”. There are 5 books in the “Expanse” series so far. If you’re a fan of the novels you’ll appreciate how closely the books are followed.TIP: The first five episodes are already available on Syfy.com. If you’re having trouble getting into the characters and plot, use those to get up to speed.The worlds created for ...... 
  4. 10/20/2015My suggestion is to stay away from PayAnywhere(dot)com  
  5. 08/07/2015Here is one for you VMWARE gurus - particularly if you run ESXi without fancy drive arrays 
  6. 08/06/2015The Killer of Orphans (Orphan Documents) 
  7. 06/02/2015Homeopathic Marketing: Traveler on my Android is now calling itself VERSE. Allow me to translate that for the IBM Notes community... 
  8. 03/17/2015A review of British Airways Premium Economy Service – How to destroy customer goodwill all at once 
  9. 02/26/2015There's a bug in how @TextToTime() and @ToTime() process date strings related to international standards and browser settings. 
  10. 01/21/2015Delivering two new presentations at Developer Camp (EntwicklerCamp) 2015 in Germany 
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.