During the past months I have worked a lot with LotusScript. One of the questions I came accross was how to add a value to a Readers or Authors field in the UI document using LotusScript. First a little background information. In daily practice, I make extensive use of Userroles in the Access Control List which are assigned to specific User Groups in the Access Control List. Based on these Userroles document access is granted based on these Userroles in the Authors and Readers Fields in the specific document.
Basic idea is to grant Edit or Read Access to specific User Groups depending on where the document is located within a certain workflow. More on that in one of the next blog posts.
In this specific case there was a value missing whereby certain groups of users were unable to read the documents.
In the example below my solution, in which the Readers Field including the new Value is stored back to the UI document using LotusScript.
Note: In the example below I get the values (uidoc.Document.GetItemValue) of two fields, Username and OrganizationalUnit, from the selected UI document in a View and add these values to a Readers Field.
The LotusScript Agent with the following code I use on selected documents in a Notes view to update the Readers (or Authors) fields.
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim s As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim fieldValue As Variant
Dim fieldValue2 As Variant
' check if document is selected
If Not ws.CurrentDocument Is Nothing Then
' document is selected
Set uidoc = ws.CurrentDocument' init
fieldValue = uidoc.Document.GetItemValue("FIELDNAME1")
fieldValue2 = uidoc.Document.GetItemValue("FIELDNAME2")
Dim item As NotesItem
Dim readersList(4) As String
readersList(0) = "[USERROLE]"
readersList(1) = fieldValue(0) '@UserName
readersList(2) = "[USERROLE]"
readersList(3) = "[" & fieldValue2(0) & "Reader]" 'OrganizationalUnit Reader(s)
'readersList(4) = "[USERROLE]"
readersList(4) = "[NEWUSERROLE]" ' New Value
If uidoc.Document.HasItem("Readers") Then
Set item = uidoc.Document.GetFirstItem("Readers")
Set item = New NotesItem(uidoc.Document, "Readers", readersList, READERS)
' save document
Call uidoc.Document.Save(True, True)
As I mentioned in a previous blog post, Quick IBM Notes Tip: Administrative LotusScript Agent to Update Field Values on Selected Documents in View ,you can also use the Agent Update Field On Selected Documents. In this case, the existing Userroles and the new value should be included in the field 'Enter Field Value' seperated with a colon.
There are always more solutions for one question.