The code below filters data in a view.
The else statement is working fine, it basically returns values for the particular user, but the if statement is where the issue is; as I want admin users to be able to view all views/records from the database.
While the if statement works, it only returns views/records for the first user, but I want it to return views for all users if the user has the Role('[Admin]').
Your help will be appreciated!
<xp:dominoView var="users" viewName="userView" keysExactMatch="true">
<xp:this.keys><![CDATA[#{javascript:var fullName = context.getUser().getFullName();
var users:NotesView = database.getView("userView");
var entryCol:NotesViewEntryCollection = users.getAllEntries();
var doc:NotesDocument = users.getFirstDocument();
var columnValues = [];
while(doc != null){
columnValues.push( doc.getItemValueString("CreatedBy") );
doc = entryCol.getNextEntry();
}
if(context.getUser().getRoles().contains('[Admin]')){
print(columnValues);
return columnValues;
}else{
return fullName;
}}]]></xp:this.keys>
</xp:dominoView>
Return an empty value return ""
for the [Admin] people. This will not set the keys property and deliver all entries in view.
Your code would look like this then:
<xp:dominoView var="users" viewName="userView" keysExactMatch="true">
<xp:this.keys><![CDATA[#{javascript:
if(context.getUser().getRoles().contains('[Admin]')){
return "";
} else {
return context.getUser().getFullName();
}
}]]></xp:this.keys>
</xp:dominoView>