@DbLookup Help

Hi,

I have created a form where I would like to retrieve some contact information from a database and display it on the form that I have created.

I have been looking at some examples for the @DbLookup formula and I’m slightly confused. I am new to this and I have tried many attempts to retrieve information from another database.

Everytime I run the formula on my form I get the following error message…

“Field: ‘Surname’: File does not exist”.

The formula I have used is…

@DbLookup(“”;“DOMAPPS1/Server”:“Contacts.nsf”;“LastName”; @Right(RequestedBy; “”);“Surname”)

I’m thinking I may have got the view bit wrong…but Im confused as to what the view bit actually is?

Any help would grately be apreciated

Thanks

Subject: @DbLookup Help

Hi

The view bit is either the alias of the view or the view’s name. I always prefer to create an alias in the format “Vxyz” and then call this in the formula.

Here is one that works for me:

@DbLookup(“”:“NoCache”;“12345678:003DC652”;“Vstaffno”;StaffNumber;“BirthdateDisplay”).

Here are some extra Notes I have made an Dblookup.

In Notes 6 there is now ‘@ServerName’ which can be used thus in Notes

@DbLookup(“”:“NoCache”;@ServerName:“xyz.nsf”;“Vcategorised”;@Subset(@DbName;-1);4))

However there are problems getting this to work in all cases so I thought I would document it.

This works on the WEB (note the server is “”)

@DbLookup(“”:“NoCache”;“”:“ptest/staffdir.nsf”;“StaffVsno”;@Right(QUERY_STRING;“=”);2)

but it won’t work in Notes !! you will need this (note the server is “xyzServer/xyzCompany”)

@DbLookup(“”:“NoCache”;“xyzServer/xyzCompany”:“ptest/staffdir.nsf”;“StaffVsno”;@Right(QUERY_STRING;“=”);2)

This will work in Notes and on the Web, but will always access the specified replica:

@DbLookup(“”:“NoCache”;“12345678:003CB0E0”;“StaffVsno”;@Right(QUERY_STRING;“=”);2)

Subject: RE: @DbLookup Help

“However there are problems getting this to work in all cases so I thought I would document it.”

It IS actually documented already. In the documentation.

@DbLookup(“”:“NoCache”; “”:“ptest/staffdir.nsf”; “StaffVsno”; @Right(QUERY_STRING;“=”); 2)

does work in the Notes client. Whenever you provide a database filepath explicitly, but leave the server empty, this piece will access a database that is local to the machine on which the code runs. When run in a scheduled agent (or through web) this will be a database on the server, when run from the client, this will be a local database.

Whenever you want to access the current database anyway, simply provide @DbName instead of “server”:“database” or - even easier - just provide an empty string. This works, no matter where the code runs.

If you enter a hard coded replica ID instead of server and filepath, be prepared to change your code whenever the replica ID might change. Also, this lookup might be performed against any replica on any server and you never have control over which replica has been used. Using the “NoCache” keyword with a lookup using the replica ID doesn’t make much sense to me, as there is no guarantee, that all replicas will be in sync (maybe except for clustered serers). In Notes 6 and up you can avoid the first problem by using @ReplicaID.

Finally let me add, that running @DbLookup against a view column given by column number is more efficient than providing a field name.