|Professional Services||Second Signal||Presentations||Andrew's Blog||Support|
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.
None of these did what we wanted. After some hacking and a little educated guesswork, I came up with this one:
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 ) ; "")
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.
Please wait while your document is saved.