notesrookie
asked on
Populating ACL information in a table within a rich text field in a document
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.CanCreateDocument s Then
createdoc = "Yes"
Else
createdoc="No"
End If
c = c + 1
myTable(i, c) = createdoc
If aclentry.CanDeleteDocument s Then
deletedoc = "Yes"
Else
deletedoc="No"
End If
c = c + 1
myTable(i, c) = deletedoc
If aclentry.CanReplicateOrCop yDocuments 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(RTE LEM_TYPE_T ABLECELL)
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(RTEL EM_TYPE_TA BLECELL)
Next
Next
Print "Done."
Call doc.Save(True, True)
Dim ws As New NotesUIWorkspace
Call ws.ViewRefresh
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.CanCreateDocument
createdoc = "Yes"
Else
createdoc="No"
End If
c = c + 1
myTable(i, c) = createdoc
If aclentry.CanDeleteDocument
deletedoc = "Yes"
Else
deletedoc="No"
End If
c = c + 1
myTable(i, c) = deletedoc
If aclentry.CanReplicateOrCop
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(RTE
For iRow% = 1 To i Step 1
For iColumn% = 1 To c Step 1
Call rtitem.BeginInsert(rtnav)
Call rtitem.AppendText(myTable(
Call rtitem.EndInsert
Call rtnav.FindNextElement(RTEL
Next
Next
Print "Done."
Call doc.Save(True, True)
Dim ws As New NotesUIWorkspace
Call ws.ViewRefresh
I like this one
http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/9290c5e7654f34ea85256a1e0050bc55?OpenDocument&Highlight=0,ACL
SOurce code included so that you can modify as needed.
http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/9290c5e7654f34ea85256a1e0050bc55?OpenDocument&Highlight=0,ACL
SOurce code included so that you can modify as needed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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.
ASKER
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.
ASKER
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.
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 :(
ASKER
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.
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
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
ASKER
Hey ya sjef - I'll open a question just for you. Thanks.
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 !