Question

i couldnt do aautocopmlete edit box. i want to take names from another database. i wrote my code to typeahead's value list. but it dont work. i am using same server but different database.anybody help me ? here is my code:

//Getting the view containing a document for each of the employees
var searchView:NotesView = session.getDatabase("servername","test/application name.nsf")
.getView("viewname");

// Creating a Lotus Notes search query. Notice the reference to lupkey!
var query = "(FIELD Ad Soyad CONTAINS *" + lupkey +"*)";

// Creating an array to store hits in
var searchOutput:Array = ["å","åå"];

// Doing the actual search
var hits = searchView.FTSearch(query);

var entries = searchView.getAllEntries();
var entry = entries.getFirstEntry();

//Sort the array manually, since Notes doesn't want to sort them alphabetically
for (i=0; i<hits; i++) {
searchOutput.push(entry.getColumnValues()[0]);
entry = entries.getNextEntry();
}
searchOutput.sort();

// Build the resulting output HTML code
var result = "<ul><li><span class='informal'>Suggestions:</span></li></ul>";

var limit = Math.min(hits,20);
for (j=0; j<limit; j++) {
var name = searchOutput[j].toString();
var start = name.indexOfIgnoreCase(lupkey)
var stop = start + lupkey.length;
//Make the matching part of the name bold
name = name.insert("</b>",stop).insert("<b>",start);
result += "<li>" + name + "</li>"; 
}

result += "</ul>";
return result;
Was it helpful?

Solution

There are plenty of issues with your code:

  1. the query can't return any result since your field has a space in it
  2. Do you really need an FTSearch to return values and not a sorted view?
  3. the typeahead -as the name suggest- presents values that match left to right and not somewhere substring. If you need that you need to roll your own typeahead function using Ajax
  4. The typeahead function doesn't take a parameter, so your lupkey doesn't go anywhere. The function needs to return all values and XPages will do the matching
  5. Instead of copying one by one into an array for sorting, copy the returning Vector() into a TreeSet(). This is one line, sorts it and removes duplicates

To get it working check this example based on dojo, previously asked here. You will need the REST control

OTHER TIPS

i do it like that var directoryTypeahead = function (searchValue:string) { // update the following line to point to your real directory

//var directory:NotesDatabase = session.getDatabase(database.getServer(), "names.nsf");

var directory:NotesDatabase = session.getDatabase(database.getServer(), "org/test.nsf");

var allUsers:NotesView = directory.getView("SVFHP2");

var matches = {};
var includeForm = {
    Person: true,
    Group: true


}

searchValue = searchValue.replace("I","i")      
var matchingEntries:NotesViewEntryCollection = allUsers.getAllEntriesByKey(searchValue, false);
var entry:NotesViewEntry = matchingEntries.getFirstEntry();
var resultCount:int = 0;


while (entry != null) {

    var matchDoc:NotesDocument = entry.getDocument();
    var matchType:string = matchDoc.getItemValueString("Form");
    //if (includeForm[matchType]) { // ignore if not person or group
        var fullName:string = matchDoc.getItemValue("Name").elementAt(0) + " " + matchDoc.getItemValue("Title").elementAt(0);
        if (!(matches[fullName])) { // skip if already stored
            resultCount++;
            var matchName:NotesName = session.createName(fullName);
            matches[fullName] = {
                cn: matchName.getCommon(),
                photo: matchDoc.getItemValueString("Photo"),
                job: matchDoc.getItemValueString("sum"),
                email: matchDoc.getItemValueString("email"),



            }
        }           
//  }
    /*if (resultCount > 15) {
        entry = null; // limit the results to first 10 found
    }
    else {*/
        entry = matchingEntries.getNextEntry(entry);
    //}
};





}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top