Created
March 16, 2017 13:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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