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.
Comment Entry |
Please wait while your document is saved.
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