//Function to determine if user can edit a document //FIRST PARAMETER IS NotesDocument, SECOND PARAMETER IS Name of authors field function isAuthor( doc:NotesDocument, authorsFieldName ) { var level = doc.getParentDatabase().getCurrentAccessLevel(); if (level >= NotesACL.LEVEL_EDITOR) { return true; //editor or higher } else if (level < NotesACL.LEVEL_AUTHOR) { return false; //reader or lower } else { //author var authors = doc.getItemValue(authorsFieldName); //field containing all document authors if (authors === null) { return false; } //no authors field present var userName = @UserName().toLowerCase(); var groupNames = context.getUser().getGroups(); //get the groups the user is in var roles = context.getUser().getRoles(); for (var i=0; i<authors.length; i++) { if (authors[i].substring(0,1) == "[") { //is a role for (var j=0; j<roles.length; j++) { if (authors[i].toLowerCase() == roles[j].toLowerCase()) { //on of user's roles is in authors field return true; }//end test for role }// end inner for }//end test for role entry else if (authors[i].toLowerCase() == userName ) { //username matches one of the values in the authors field return true; } else if (!groupNames.isEmpty()){ //test if group the user is in is in the authors field for (var j=0; j<groupNames.length; j++ ){ if (authors[i].toLowerCase()==groupNames[j].toLowerCase() ){ return true; } } } } } return false; }