Removing a document link

5 pts.
Tags:
LotusScript
NotesRichTextLink
Remove Link
I have a notes application in which users can open request tickets to have work performed. They also have the ability to create subrequests or the original ticket. When this is done, a document link is created in the original ticket that links to the subrequest. The problem is that for some reason, some of the document links in the original request have gotten duplicated, meaning that there are mutltiple links all pointing to the same subrequest. I would like to remove the duplicate links. I have written an agent that will look for the duplicate links, and when found, I am doing the remove method but it doesnt seem to be working.  I am including the code for the agent below. Hopefully this is enough information that someone can provide some suggestions. Thanks in advance, Tom Disclaimer:  I am a LotusScript novice so keep that in mind when reviewing the code below.
    Sub Initialize
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim collection As NotesDocumentCollection
    Dim doc As NotesDocument
    Dim rti As NotesRichTextItem
    Dim rtnav As NotesRichTextNavigator
    Dim rtlink As NotesRichTextDocLink
    Dim links(1 To 20) As String
    Dim item As NotesItem
    Dim reqno As String
    Dim j As Integer
    Dim i As Integer
    Dim x As Integer
    Dim ir
    
    Set db = session.currentdatabase 
    Set collection = db.AllDocuments
    
    ' Get the document
    For j = 1 To collection.Count
        Set doc = collection.GetNthDocument( j )
        
        'for each request, need to look at the links fields to see if any dupliate links
        'exist. for any that are found, then remove the duplicates
        
        If doc.Form(0) = "NewRequest" Then
            
            'set rich text item to the doc link field
            Set rti = doc.GetFirstItem("SubTaskLink1")
            If Not rti Is Nothing then
                Set rtnav = rti.CreateNavigator
                Set rtlink = rtnav.GetFirstElement(RTELEM_TYPE_DOCLINK)
                i = 1
                x = 0
                Erase links            'clear array
                
                Do While not rtlink Is Nothing 
                    'look for request no. in array
                    ir = ArrayGetIndex(links,rtlink.DisplayComment)
                    
                    'if request no. not found, then load into array
                    If Not IsNumeric(ir) then
                        links(i) = rtlink.DisplayComment
                        i = i + 1
                    Else    
                        'if it was found, then this link is duplicate and should be removed
                        x = x + 1
                        rtlink.remove
                    End If
                    ir = ""
                    Set rtlink = rtnav.Getnextelement(RTELEM_TYPE_DOCLINK)
                Loop
                
                'If duplicate links were found, Then save document
                If x > 1 Then
                    Call doc.Save( True, True )
                End If
            End If
            
        End If
    Next
End Sub


Software/Hardware used:
Designer 8.5
ASKED: December 16, 2011  8:55 PM
UPDATED: February 28, 2012  2:55 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following