Skip to content

Instantly share code, notes, and snippets.

Created March 16, 2017 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/592085c32822da3d7cb73ed04e0156b9 to your computer and use it in GitHub Desktop.
Save anonymous/592085c32822da3d7cb73ed04e0156b9 to your computer and use it in GitHub Desktop.
SSJS script to populate a list from documents in a IBM Notes DB for type-ahead function
var idTypeAhead = function (searchValue:string) {
var nsf_structure = "apps\\crm.nsf";
var directory:NotesDatabase = session.getDatabase(session.getServerName(), nsf_structure);
var vw:NotesView = directory.getView("lkupByID");
//matches = type Hash, no order !!
var matches = {};
var matchOrder = [];
var includeForm = {
customer: true
}
var matchingEntries:NotesViewEntryCollection = vw.getAllEntriesByKey(searchValue, false);
var entry:NotesViewEntry = vw.getEntryByKey(searchValue);
if (entry != null){
var nav:NotesViewNavigator = vw.createViewNavFrom(entry);
var entry:NotesViewEntry = nav.getFirst();
var resultCount:int = 0;
while (entry != null) {
var matchDoc:NotesDocument = entry.getDocument();
var matchType:string = matchDoc.getItemValueString("Form");
if (includeForm[matchType]) {
var sID:string = matchDoc.getItemValue("emAlias").elementAt(0);
if (!(matches[sID])) { // skip if already stored
resultCount++;
var matchid:String = sID;
matches[matchid] = {
id: matchid,
fname: matchDoc.getItemValueString("emFirstName"),
lname: matchDoc.getItemValueString("emLastName"),
job: matchDoc.getItemValueString("emDeptDesc"),
email: matchDoc.getItemValueString("emEmail")
};
matchOrder.push(matchid);
}
}
if (resultCount > 10) {
entry = null;
} else {
var tmpentry = nav.getNext();
entry.recycle();
entry = tmpentry;
}
}
}
var returnList = "<ul>";
for (var i=0;i<matchOrder.length;i++){
var match = matches[matchOrder[i]];
var matchDetails:string = [
"<li>",
"<span hidden>" + match.id + "</span>"
"<span class=\"informal\">",
"<h5>" + match.fname + " " + match.lname + "</h5>",
"<p class='small'><mark>" + match.id + "</mark><br/>",
match.job + "<br/>",
match.email +"</p>",
"</span>",
"</li>"
].join("");
returnList += matchDetails;
}
returnList += "</ul>";
return returnList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment