programmatically adding a user into lotus notes group
<p>I have a database that keeps contracts and each contract have an attached document file.<br>
My task is to make users without access to the database able to access specific contracts and its attachments.<br>Thus, the special access button.<br>
I added a special access button to the form that gives access to default users.<br>I was able to give them access up to the contract but I am not able to give them access to the attached document.<br>Upon further investigation, I found out that the form associated with the attached document is restricted to be viewed with users with role/s read, author, and siteadmin only.<br>The solution I should do is to create a new role (addreader) and create a group that have the addreader role.<br>
when users are addedd via the special access button, the user/s should be added to the notes group with addreader role.<br>My problem here is how to add the user in the group.<br>I am a beginner in lotus notes and i am hoping for some help. <br><br>Thanks in advance.</p>

<p>CODE STARTS HERE:</p>

<pre><code>Sub Initialize

    AGENT_NAME = "wqs-DocAccess"
    ERROR_ON = True

    If (ERROR_ON) Then On Error Goto Error_Handler

    Call initObjects()                      ' Set global variables

    Call ProcessAccess()

    Exit Sub

Error_Handler:          ' Error handling
    Call ErrorHandler(Err(), Error$(), "Initialize sub", Erl())

End Sub
Sub ProcessAccess()
    ' This sub will inspect the given effective date range and enforce it for this web submit.

    If (ERROR_ON) Then On Error Goto Error_Handler

    Dim scanDoc As NotesDocument
    Dim nItem As NotesItem

    Dim vStart As Variant
    Dim vEnd As Variant
    Dim vEntries As Variant                                 ' Array of strings

    Dim strUser As String
    Dim strCanonUser As String
    Dim strDESUnid As String
    Dim strDuration As String

    Dim doRemove As Integer                             ' Boolean:  Default = False

    strUser = webDoc.GetItemValue("UserName")(0)
    strCanonUser = Session.CreateName(strUser).Canonical
    strDESUnid = webDoc.GetItemValue("DesDocID")(0)

    If (webDoc.GetItemValue("RemoveAccess")(0) = "Yes") Then doRemove = True

    ' Determine date range
    vStart = webDoc.GetItemValue("AccessBeginDate")(0)
    strDuration = webDoc.GetItemValue("Duration")(0)

    ' Required fields on Access Doc have been filled out - continue inspection 
    vEnd = Evaluate(|@Adjust([| &amp; Format$(vStart, "mm/dd/yyyy") &amp; |]; 0; 0; | &amp; Val(strDuration) - 1 &amp; |; 0; 0; 0)|)
    vEnd = vEnd(0)

    ' Store info in the event an error occurs trying to retrieve DES
    strErrorInfo = "DES UNID = " &amp; strDESUnid &amp; "; User = " &amp; strUser &amp; "; AccessDoc UNID = " &amp; webDoc.UniversalID

    ' Retrieve DES doc
    Set desDoc = getDESDoc(strDESUnid)
    If (desDoc Is Nothing) Then
        Error 6020, "ERROR:  Could not find related DES doc upon saving the Access doc"     ' Should never happen.
    End If

    ' Continue inspection of effective date range and be sure is enforced on DES
    vEntries = desDoc.GetItemValue("AllowAccess")

    If ((Today &gt;= vStart And Today &lt;= vEnd) And (Not doRemove)) Then
        ' In scope, be sure name and Access UNID are in DES
        If Not (isStringInArray(strUser, vEntries)) Then
            ' User should have access, but is not listed -- stamp name on DES
            Call desDoc.ReplaceItemValue("AllowAccess", AddStringToArray(strUser, vEntries))

            Call desDoc.ReplaceItemValue("AllowAccessDocID", _
            AddStringToArray(webDoc.UniversalID, desDoc.GetItemValue("AllowAccessDocID")))

            ' Add name to Readers field on DES
            Call desDoc.ReplaceItemValue("WhoCanRead", _
            AddStringToArray(strCanonUser, desDoc.GetItemValue("WhoCanRead")))

            ' BSM 09/08/2004:  Also add name to Readers field on Scan doc (if one exists)
            Set scanDoc = getScanDoc(desDoc)
            If Not (scanDoc Is Nothing) Then
                Call scanDoc.ReplaceItemValue("WhoCanRead", _
                AddStringToArray(strCanonUser, scanDoc.GetItemValue("WhoCanRead")))
                Call scanDoc.Save(True, True)
            End If

            Call StampAccessHistory(desDoc, Format$(Now, "mm/dd/yyyy") &amp; " -- Name added: " &amp; strUser)
            Call desDoc.Save(True, True)
        End If
    Else
        ' Out of scope, be sure name and Access UNID are *not* in DES
        If (isStringInArray(strUser, vEntries)) Then
            ' ERROR -- User has access, but should not! -- Remove user name stamp from DES.
            Call RemoveAccessNameFromDES(strUser, strDESUnid, False)
        End If

        If (vEnd &lt; Today) Then
            Call webDoc.ReplaceItemValue("Expired", "Yes")
        End If

        ' Note:  If user clicked "Remove", then the daily agent will delete it the next day (cannot delete webDoc if the DocumentContext)

    End If

    ' Copy editors field over from DES doc  
    Set nItem = desDoc.GetFirstItem("WhoCanEdit")
    Call webDoc.CopyItem(nItem, "")                     

    Exit Sub

Error_Handler:          ' Error handling
    Call ErrorHandler(Err(), Error$(), "ProcessAccess sub", Erl())

End Sub
Sub initObjects()
    ' This sub will set certain global variables

    If (ERROR_ON) Then On Error Goto Error_Handler

    Call InitSession()          ' Invoke shared function

    Set webDoc = Session.DocumentContext

    Exit Sub

Error_Handler:          ' Error handling
    Call ErrorHandler(Err(), Error$(), "initObjects sub", Erl())

End Sub
</code></pre>