Domino Code Fragment

Code Name*
Agent used to create User Profile Documents From Office Profile Documents
Date*
04/29/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.15.156.140
Description*
Build a set of documents from information gathered from a different set of documents.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
This agent is set to run on a Form "Office Profile" whenever one is added or updated or it can be run manually. It assumes the following fields exist on the "Office Profile" form (alias = OffProf): Code (as text editable) Offowner (as keyword - editable from NAB) least secure user OffAdmins (as keyword - editable from NAB) Lev3users (as keyword - editable from NAB) Lev2users (as keyword - editable from NAB) Lev1users (as keyword - editable from NAB) most secure user It assumes the following fields on the "User Profile" form (alias = UserProf): UserName (as keyword - editable from NAB) PrimeOffice (as text editable) AutoAlert (as keyword - editable) AutoRemdr (as keyword - editable) Defsig ( as text - editable) PastEditDates (as text - computed (@Text(@Now))
PastAuthors (as authors - computed (@Name([CN]; @Username))) The Office owner is limited to only allow one user name, while all other fields on the "Office Profile" allow multiple names to be entered. Therefore the sub Addnames is used to build and array of those fields that contain more than one entry.
Files/Graphics attachments (if applicable): Code:
Sub Initialize
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim collection As NotesDocumentCollection
    Dim usercollection As NotesDocumentCollection
    Dim dateTime As NotesDateTime
    Dim doc As NotesDocument
    Dim udoc As NotesDocument
    Dim bound As Integer
    Dim j As Integer
    Dim i As Integer
    Dim x As Integer
    Dim allnames As Variant
    Dim getname As Variant
    Dim testname As String
    Dim testname2 As String
    Set db = session.CurrentDatabase
    Set dateTime = New NotesDateTime("01/01/97")
   
    'Collect all "Office Profile" documents not processed by this agent
    Set collection = db.UnprocessedDocuments


 
   ' Set counter to iterate through unprocessed "Office Profile" documents using the "Office Owner" Field
    For j = 1 To collection.Count
         Set doc = collection.GetNthDocument( j )
         allnames = doc.GetItemValue( "OffOwner" )
         Gosub userdocs
    Next j
   
    ' Set counter to iterate through unprocessed "Office Profile" documents using the "Office Administration" Field
    For j = 1 To collection.Count
         Set doc = collection.GetNthDocument( j )
         allnames = doc.GetItemValue("OffAdmins")
         Gosub userdocs
    Next j
   
     ' Set counter to iterate through unprocessed "Office Profile" documents using the "Groups Limited" Field    
    For j = 1 To collection.Count
         Set doc = collection.GetNthDocument( j )
         allnames = doc.GetItemValue("Lev3Users")
         Gosub userdocs
    Next j
   
    ' Set counter to iterate through unprocessed "Office Profile" documents using the "Public Users" Field
    For j = 1 To collection.Count

          Set doc = collection.GetNthDocument( j )
         allnames = doc.GetItemValue("Lev2Users")
         Gosub userdocs
    Next j
   
    ' Set counter to iterate through unprocessed "Office Profile" documents using the "Limited Users" Field
    For j = 1 To collection.Count
         Set doc = collection.GetNthDocument( j )
         allnames = doc.GetItemValue("Lev1Users")
         Gosub userdocs
    Next j
   
    ' Goto Processdocs to iterate through unprocessed docs and change them to processed
    Goto processdocs
   
    ' Section of code to build user documents
Userdocs:
    bound% = Ubound(allnames)
    For  v = 0  To bound
         testname = allnames(v)
         If testname  <> "" Then
              selection$  = "Form = ""UserProf"""
         ' Collect all "User Profile" documents
              Set usercollection = db.Search(selection$, datetime, 0 )
              x = 0
              For i = 1 To usercollection.Count
                   Set udoc = usercollection.GetNthDocument(i)

                    getname = udoc.GetItemValue("Username")
                   testname2 = getname(0)
                   If testname2 =  testname Then
                        x = (x + 1)
                   End If
              Next i
              If x = 0 Then
              ' Define ndoc as New Document using "User Profile" form and fill in fields
                   Dim ndoc As New NotesDocument( db )
                   ndoc.Form = "UserProf"
                   ndoc.UserName =  allnames(v)
                   ndoc.Primoffice =  doc.GetItemValue("Code")
                   ndoc.Autoalert = "OFF"
                   ndoc.Autoremdr = "No"
                   ndoc.defsig = "Best Regards"

                    ndoc.PastEditDates = Evaluate("@Text(@Now)")
                   ndoc.PastAuthors = Evaluate("@Name([CN]; @Username)")

              ' Save current "User Profile" document
                   Call ndoc.Save( True, True)              
              Else
              End If
         End If
    Next v
    Return
   
    ' Mark documents as processed
Processdocs:
    For j = 1 To collection.Count
         Set doc = collection.GetNthDocument( j )

          ' Save current "Office Profile" document
         Call doc.Save( True, True )
         ' Mark current Office Profile document as processed
         Call session.UpdateProcessedDoc( doc )  
    Next j
End Sub