We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Populating ACL information in a table within a rich text field in a document

notesrookie
notesrookie asked
on
Medium Priority
340 Views
Last Modified: 2013-12-18
Most learned experts,

I am trying to write an agent that will generate a table in the body of a document. I know for sure that there will be 7 columns for the ACL information that I am looking for and am gathering the information within a 2D string array. I'm getting a subscript out of range error. My code is below. Am using v5.0.12. If someone could straighten me out, it would be greatly appreciated. And if there is a simpler way to execute this that would be appreciated as well. Many thanks.

Dim db As New NotesDatabase( "notes_server", "thisdb.nsf" )
      Dim doc As NotesDocument
      Dim rtitem As NotesRichTextItem
      Dim acl As NotesACL
      Dim aclentry As NotesACLEntry
      Dim usrname As String, usertype As String, level As String, createdoc As String, deletedoc As String, repldoc As String
      Dim anyroles As String, stmt As String
      Dim i As Integer      'row count
      Dim c As Integer      'column count
      
      Set doc = New NotesDocument(db)
      doc.Form = "Main Topic"
      doc.From = "Current User"
      doc.Subject = "Current database ACL"
      
      Set rtitem = New NotesRichTextItem( doc, "Body" )
      Set acl = db.ACL
      Set aclentry = acl.GetFirstEntry
      i = 0
      Redim myTable(i, 6) As String
      
      While Not (aclentry Is Nothing)      
            
            usrname = Cstr(aclentry.Name)
            c = 0
            myTable(i, c) = usrname
            
            Select Case aclentry.UserType
            Case 0: usertype = "Unspecified"
            Case 1: usertype = "Person"
            Case 2: usertype = "Server"
            Case 3: usertype = "Mix group"
            Case 4: usertype = "Person group"
            Case 5: usertype = "Server group"
            End Select
            c = c + 1
            myTable(i, c) = usertype
            
            Select Case aclentry.Level
            Case 0: level = "No Access"
            Case 1: level = "Depositor"
            Case 2: level = "Reader"
            Case 3: level = "Author"
            Case 4: level = "Editor"
            Case 5: level = "Designer"
            Case 6: level = "Manager"
            End Select
            c = c + 1
            myTable(i, c) = level
            
            If aclentry.CanCreateDocuments Then
                  createdoc = "Yes"
            Else
                  createdoc="No"
            End If
            c = c + 1
            myTable(i, c) = createdoc
            
            If aclentry.CanDeleteDocuments Then
                  deletedoc = "Yes"
            Else
                  deletedoc="No"
            End If
            c = c + 1
            myTable(i, c) = deletedoc
            
            If aclentry.CanReplicateOrCopyDocuments Then
                  repldoc = "Yes"
            Else
                  repldoc="No"
            End If
            c = c + 1
            myTable(i, c) = repldoc
            
            Forall r In aclentry.Roles
                  If r = "" Then
                        anyroles = ""
                  Else
                        anyroles = anyrole & ", " & r      
                  End If
                  c = c + 1
                  myTable(i, c) = anyroles
            End Forall
            
            i = i + 1
            Redim Preserve myTable(i, 6) As String  <-- this iis where I am encountering the error
            Set aclEntry = acl.GetNextEntry( aclentry )
            
      Wend
      
      Call rtitem.AppendTable(i, c)
      Dim rtnav As NotesRichTextNavigator
      Set rtnav = rtitem.CreateNavigator
      Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
      For iRow% = 1 To i Step 1
            For iColumn% = 1 To c Step 1
                  Call rtitem.BeginInsert(rtnav)
                  Call rtitem.AppendText(myTable(i,c))
                  Call rtitem.EndInsert
                  Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
            Next
      Next
      
      Print "Done."
      Call doc.Save(True, True)
      Dim ws As New NotesUIWorkspace
      Call ws.ViewRefresh
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
Why not use some free tools to get this info.

See LDD
http://www-10.lotus.com/ldd/sandbox.nsf?OpenDatabase
Search for ACL

there are a couple of good ones including one from IBM that allow export to Excel.

I hope this helps !
CERTIFIED EXPERT
Top Expert 2007

Commented:
Commented:
Hi notesrookie,
The reason why you get the error is:

If you do include Preserve in a ReDim statement, the only bound that LotusScript lets you change (by incrementing) is the upper bound of the last array dimension.
You cannot change the number of dimensions of an array or the data type of its elements with a ReDim statement.

So I suggest you to make the first dymension constant and increment the second one.
Like this:



Sub Click(Source As Button)
   
    Dim db As New NotesDatabase( "notes_server", "thisdb.nsf" )
    Dim doc As NotesDocument
    Dim rtitem As NotesRichTextItem
    Dim acl As NotesACL
    Dim aclentry As NotesACLEntry
    Dim usrname As String, usertype As String, level As String, createdoc As String, deletedoc As String, repldoc As String
    Dim anyroles As String, stmt As String
    Dim iRow As Integer, iColumn As Integer
    Dim i As Integer     'row count
    Dim c As Integer     'column count
    Dim myTable() As String
   
    Set doc = New NotesDocument(db)
    doc.Form = "Main Topic"
    doc.From = "Current User"
    doc.Subject = "Current database ACL"
   
    Set rtitem = New NotesRichTextItem( doc, "Body" )
    Set acl = db.ACL
    Set aclentry = acl.GetFirstEntry
    i = 0
    Redim myTable(6, i) As String
   
    While Not (aclentry Is Nothing)    
       
        usrname = Cstr(aclentry.Name)
        c = 0
        myTable(c, i) = usrname
       
        Select Case aclentry.UserType
        Case 0: usertype = "Unspecified"
        Case 1: usertype = "Person"
        Case 2: usertype = "Server"
        Case 3: usertype = "Mix group"
        Case 4: usertype = "Person group"
        Case 5: usertype = "Server group"
        End Select
        c = c + 1
        myTable(c,i) = usertype
       
        Select Case aclentry.Level
        Case 0: level = "No Access"
        Case 1: level = "Depositor"
        Case 2: level = "Reader"
        Case 3: level = "Author"
        Case 4: level = "Editor"
        Case 5: level = "Designer"
        Case 6: level = "Manager"
        End Select
        c = c + 1
        myTable(c,i) = level
       
        If aclentry.CanCreateDocuments Then
            createdoc = "Yes"
        Else
            createdoc="No"
        End If
        c = c + 1
        myTable(c, i) = createdoc
       
        If aclentry.CanDeleteDocuments Then
            deletedoc = "Yes"
        Else
            deletedoc="No"
        End If
        c = c + 1
        myTable(c, i) = deletedoc
       
        If aclentry.CanReplicateOrCopyDocuments Then
            repldoc = "Yes"
        Else
            repldoc="No"
        End If
        c = c + 1
        myTable(c, i) = repldoc
       
        Forall r In aclentry.Roles
            If r = "" Then
                anyroles = ""
            Else
                anyroles = anyroles & ", " & r
            End If
            c = c + 1
            myTable(c, i) = anyroles
        End Forall
       
        i = i + 1
        Redim Preserve myTable(6, i) As String  '<-- this iis where I am encountering the error
        Set aclEntry = acl.GetNextEntry( aclentry )
       
    Wend
   
    Call rtitem.AppendTable(c, i)
    Dim rtnav As NotesRichTextNavigator
    Set rtnav = rtitem.CreateNavigator
    Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
   
    For iRow% = 0 To c - 1
       
        For iColumn% = 0 To i - 1
           
            Call rtitem.BeginInsert(rtnav)
            Call rtitem.AppendText(myTable(iRow, iColumn))            
            Call rtitem.EndInsert            
            Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
        Next
    Next
   
    Print "Done."
    Call doc.Save(True, True)
    Dim ws As New NotesUIWorkspace
    Call ws.ViewRefresh
End Sub



Hope this helps,
Marko

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
I think a 1D-array would be enough. Why you need the column number I don't understand. You can create one string, where all values are separated by commas. If need be, you can split that string in a later stage using
    Split(myTable(i), ",")

Furthermore, why do you need the array? To separate information gathering and generating output? Then I suggest to do all in one go, you create separate Subs for both functionalities. If need be, you use two Classes for that purpose.

Author

Commented:
sjef - I am working, unfortunately, in v5.0.12 and will not be able to take advantage of the Split function. I thought that using an array would be a neat way to collect the information and then display it in a quick table in a document. Not sure what you meant by "do it all in one go". Please elaborate. Thanks.

Author

Commented:
Marko - The solution did get me past the "subscript out of range" line. However, there are 15 ACL entries in the database with 7 related acl items. Currently the table creation portion of it is creating a 15 x 7 table. I'd like a 7 x 15 table created with the data populating it accordingly. Any ideas? Thanks.

Author

Commented:
Marko - Thanks. I got it. I switched the irow and icolumn statements. And since you were spot on with your answer, i'll award you the points.
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Okay, there's no split, but you could write one yourself... There is one in EE already somewhere, but you don't need it anymore :(

Author

Commented:
Acutally sjef - I'm glad you mentioned it. I don't know when I'll be upgrading to R6 so I'll look it up. As always I appreciate receiving comments.
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
I'm in a generous mood...

Function MySplit(Byval r As String, s As String) As Variant ' don't call it Split!
    Dim i As Integer
    Dim v As Variant
    Dim n As Integer

    Redim v(0)
    i= Instr(r,s)
    Do While i>0
        Redim Preserve v(n)
        v(n)= Left(r,i-1)
        r= Mid(r,i+Len(s))
        i= Instr(r,s)
        n= n+1
    Loop
    Redim Preserve v(n)
    v(n)= r
    MySplit= v
End Function

Author

Commented:
Hey ya sjef - I'll open a question just for you. Thanks.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.