Reputation: 5135
Is there a way to set the documents visible in the view for only specific users? I have a namesPicker which takes all the users from the names.nsf database, and I want to allow the creator of the document to put a protection on the document. The creator of the document would select which user/s from the names.nsf database can see the document in the view, and open it. Is there a way to do this?
I am thinking that with the namesPicker I only get a string value of the names of the users, and how can I put then the document protected for those specific users?
I have already created the document, the only thing missing is this protection issue, which I think will not be easy to accomplish.
Upvotes: 0
Views: 202
Reputation: 30960
Use setReaders(true)
for your document item
var doc = document1.getDocument(true);
var item:NotesItem = doc.replaceItemValue("Readers", namesPickerValue);
item.setReaders(true);
This gives your item the "readers" property. Only people or groups listed in this field are allowed to read the document.
namesPickerValue
can be String or an Array of Strings or a Vector or a List. Make sure the names are canonically like "CN=Knut Herrmann/O=Leonso" or as a common name like "Knut Herrmann" (not recommended). The format "Knut Herrmann/Leonso" doesn't work.
Here is a sample code for converting names listed in field "inputText1" to canonical format and to write into Readers item as readers field:
var doc = document1.getDocument(true);
var value = getComponent("inputText1").getValue();
var array = [];
if (typeof value === "string") {
var name = session.createName(value);
array.push(name.getCanonical());
name.recycle();
} else {
var it:java.util.Iterator = value.iterator();
while(it.hasNext()) {
var name = session.createName(it.next());
array.push(name.getCanonical());
name.recycle();
}
}
var item:NotesItem = doc.replaceItemValue("Readers", array);
item.setReaders(true);
Upvotes: 4