Domino Code Fragment

Code Name*
Using a dialog box allow a manager to assign roles to a readers field on the fly to various documents
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.224.214.215
Description*
This code allows a db Manager to assign various roles on the fly to a readers field on the document. The roles are called from a (GetRoles) form that is used as a dialog box to allow th euser to select various roles in the ACL.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
You need a form call (GetRoles) that has two fields. In the PostOpen of this form we have the following code to read the Roles in the db ACL Sub Postopen(Source As Notesuidocument)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim sRoles As Variant
Dim acl As NotesACL
Dim item As NotesItem
Dim doc As NotesDocument
Set doc = Source.Document
Set db = session.CurrentDatabase
Set item = doc.GetFirstItem( "GetRoles" )
item.values = ""
Set acl = db.ACL
Call item.AppendToTextList( acl.Roles )
Call Source.RefreshHideFormulas
Call Source.Refresh
End Sub Field one is GetRoles and is a text multivalue field computed to @Trim(@Replace(GetRoles; "[Managers]"; "")) In the above we disallow the user from asigning the [Managers] Role. Field two is Readers and is a multivalue keyword field that calls the GetRoles field.
Files/Graphics attachments (if applicable): Code:
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Set db = session.CurrentDatabase
' Collection of selected documents in the view fro agent to run on.
Set collection = db.UnprocessedDocuments
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
' Container for roles that uers will select from our dialog box.
Dim vReaders As Variant
Dim item As NotesItem
Dim vSecurity As Variant

' Here we open the document that user is sitting on so that we can capture input from dialog box
Set uidoc = ws.EditDocument( True )
' We set Saveoptions field on uidoc so that we are not prompted during close of uidoc
' It will be forced back to a value of 1 in the QueryClose event of the documents form
Call uidoc.FieldSetText("SaveOptions", "0")
' Open our Dialog form that allows user to select roles from the current db
Call ws.DialogBox ( "(GetRoles)", True, True, True, False, False, False, "Update Document Readers" )

' Assign doc handle to uidoc so we can see what user selected from dialog box
Set doc = uidoc.document
' Check the readers field to see what was passed back
vReaders = doc.Readers
' Close our uidoc as it is no longer needed
Call uidoc.close
' Variable to check first element to ensure that user selected something in the dialog box
Dim testreaders As String
testreaders = vReaders(0)

' Reader deselected all rolls so lets make sure that the only roll left on the documents is the [Manager] role
If testreaders = "" Then
For i = 1 To collection.Count
Set doc = collection.GetNthDocument( i )
' Assign [Managers] role to readers field
doc.Readers = "[Managers]"
Set vSecurity = doc.getfirstitem("Readers")
' Ensure security on field is set
vSecurity.isreaders = True
Call doc.save(False, True)
Next i
Else
' Ready to set Readers field on all selected documents

For i = 1 To collection.Count
Set doc = collection.GetNthDocument( i )
' Set Readers field to output of dialog box
doc.Readers = vReaders
Set item = doc.GetFirstItem( "Readers" )
' Append [Managers] role to readers field
Call item.AppendToTextList( "[Managers]" )
Set vSecurity = doc.getfirstitem("Readers")
' Ensure security on field is set
vSecurity.isreaders = True
Call doc.save(False, True)
Next i
End If

End Sub