Examples: Accessing data outside the current document and database

  1. This example looks up a person name in the People view of the local Address Book (names.nsf) and gets the office phone number in the document containing that name.
    inputName := @Prompt([OkCancelEdit]; "User name"; "Enter user name as FIRST LAST"; "");
    adjName := @Right(inputName; " ") + " , " + @Left(inputName; " ");
    phoneNumber := @DbLookup("Notes" : "NoCache"; "" : "NAMES"; "People"; adjName; "OfficePhoneNumber");
    @Prompt([Ok]; "Office phone number"; inputName + "'s office phone is " + phoneNumber)
  2. This example is the same as the first, with two exceptions. The replica ID of an Address Book database is used instead of a specific name. Notes® will search for the replica locally and then on servers, and use the first database it finds with that replica. The last parameter to @DbLookup is column 2 instead of the OfficePhoneNumber. Effectively this is the same, because column 2 contains the phone number.
    inputName := @Prompt([OkCancelEdit]; "User name"; "Enter user name as FIRST LAST"; "");
    adjName := @Right(inputName; " ") + " , " + @Left(inputName; " ");
    phoneNumber := @DbLookup("Notes" : "NoCache"; "85255AD6:006AE971"; "People"; adjName; 2);
    @Prompt([Ok]; "Office phone number"; inputName + "\'s office phone is " + phoneNumber)
  3. This example looks up the member names for a group in the Groups view of the local Address Book.
    groupName := @Prompt([OkCancelEdit]; "Group name"; "Enter group name"; "");
    members := @DbLookup("Notes" : "NoCache"; "" : "NAMES"; "Groups"; groupName; "Members");
    @Prompt([OkCancelList]; "Group members"; "Members of " + groupName; ""; members)
  4. This example gets the associated person name in the local Address Book, given an office phone number. It is designed to work where one number serves exactly one person. Since the database does not have a view sorted by phone number, the example uses @DbColumn to get all phone numbers (column 2) and all persons (column 1), then finds the person that corresponds to the number.
    phone := @Prompt([OkCancelEdit]; "Phone number"; "Enter phone number"; "");
    phoneList := @DbColumn("Notes" : "NoCache"; "" : "NAMES"; "People"; 2);
    nameList := @DbColumn("Notes" : "NoCache"; "" : "NAMES"; "People"; 1);
    position := @Member(phone; phoneList);
    @If(position = 0; @Do(@Prompt([Ok]; "Not listed"; "No listing for " + phone); @Return(" " )); "");
    name := @Subset(@Subset(nameList; position); -1);
    nameAdj := @Right(name; " ") + " " + @Left(name; ",");
    @Prompt([Ok]; "Phone number " + phone; nameAdj)