Home > Domino Tips > Developer > Managing Lotus Notes doclinks with LotusScript
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Managing Lotus Notes doclinks with LotusScript


Benoit Dubuc
02.20.2007
Rating: -2.76- (out of 5)


Lotus Notes, Domino, Workplace and WebSphere tips and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


This LotusScript code finds all the doclinks in a Lotus Notes application and validates them. It also determines whether or not the target document is still in the Lotus Notes database.

To begin, use the code below to create a "Link Info" document for each doclink encountered. This needs to be in an agent that runs on all the documents in the Lotus Notes database:

Sub Initialize
'scan all fields to find rich text items 
and see if we have doclinks in them
 
Dim session As NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim rti As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim rtlink As NotesRichTextDocLink
Dim LinksDB As NotesDatabase
Dim LinkDoc As NotesDocument

Set session = New NotesSession
Set LinksDB = session.CurrentDatabase
If Not LinksDB.isOpen Then 
Msgbox "Cannot locate Links DB.  Process ended."
Exit Sub
End If
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument
 
While Not doc Is Nothing
'scan all items for Rich Tex t Fields
Forall i In doc.Items
If i.type =  1 Then
'scan the RTI for doc links (gets all links)   
Set rti = doc.GetFirstItem(i.name)
Set rtnav = rti.CreateNavigator
If rtnav.FindFirstElement
(RTELEM_TYPE_DOCLINK) Then
Do
Set rtlink = rtnav.GetElement
If rtlink.ServerHint = "" Then
 server$ = "Local"
Else
server$ = rtlink.ServerHint
End If
'get link info
Set LinkDoc = LinksDB.createdocument
linkDoc.form="LinkInfo"
linkDoc.Linkcomment = rtlink.DisplayComment
linkDoc.FoundInTitle = doc.title
linkDoc.FoundInUNID = doc.UniversalID
linkDoc.FoundForm = doc.form(0)
linkDoc.lcPhase = doc.lcPhase
linkDoc.cboProcess = doc.cboProcess
linkDoc.FoundIn = i.name
linkDoc.Server = server$
linkDoc.ReplicaID = rtlink.DbReplicaID
If  rtlink.ViewUNID <> String$(32, "0") Then
 
linkDoc.ViewUNID = rtlink.ViewUNID
End If
If  rtlink.DocUNID <> String$(32, "0") Then
linkDoc.DocUNID = rtlink.DocUNID
End If
Call linkdoc.save (True, False, True)
Loop While rtnav.FindNextElement
End If
End If
End Forall
Set doc = dc.GetNextDocument(doc)
 Wend
End Sub

Next, we need to use an agent that will try to open up those doclinks to see if the target doc is still in the Lotus Notes database. But first, you'll need to create a view that will show all "Link Info" documents, sorted by DocUNID:

Sub Initialize
'for all links, see if we can 
open the document/view/base

On Error Goto error_trap

Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim DB As NotesDatabase
Dim doc As NotesDocument
Dim view As NotesView
Dim TargetDB As New NotesDatabase( "", "" )
Dim TargetDoc As NotesDocument
Dim server As String
Dim i As Integer, count As Integer
Dim prevstatus As Double

Set db = session.CurrentDatabase
Set view = db.GetView( "LinksLookup" ) 
 'created to show the documents 
created by the previous agent
count = view.AllEntries.Count
Set view = db.GetView("(AllByDocID)")  
'needed to do a lookup
i=1
Set doc = view.GetFirstDocument
'---------------------------------------------------
------------------------------------------------------------   
'FOR NOW, ASSUME ALL LINKS 
ARE IN THIS DB
'If TargetDB.OpenByReplicaID
( server, doc.ReplicaID(0) ) Then
Set targetdb = db
'---------------------------------------------------
------------------------------------------------------------ 
While Not doc Is Nothing
If doc.hasitem("linkstatus") Then
prevstatus = doc.linkstatus(0)
Else
prevstatus = 999
End If
'see if DocUNID is not blank
If doc.docunid(0) <> "" Then
'can we get the Doc?
server = doc.server(0)
If Ucase(server) = "LOCAL" Then server = ""
'try to open the document
Set targetdoc = 
TargetDB.GetDocumentByUNID(doc.DocUNID(0) )
If targetDoc Is Nothing Then
doc.LinkStatus = 81  'not found
Else
doc.LinkStatus = 82  'found
End If
 Else
 'external link
 doc.linkstatus = 112
 End If
If doc.linkstatus(0) <> prevstatus 
Then Call doc.save(True, False, True) 
'so we don't generate useless replication
i=i+1
 
Set doc = view.GetNextDocument(doc)
Wend
Set targetdb = New NotesDatabase( "", "" )

Exit Sub

error_trap:
If Err = 4091 Then  'invalid UniversalID 
so we have an invalid doclink
Set targetdoc = Nothing
Resume Next
Else
Print "Error " + Cstr(Err) + 
" at line " + Cstr(Erl) + " : " + Error
Exit Sub
End If
 
 
End Sub

Last comes the tricky part of the effort. You may have images that have link hotspots on them that you want to validate. Here's a nifty way of doing it through DXL (Lotus Notes 6.5 or higher is required):

Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim exporter As NotesDXLExporter
Dim importer As NotesDXLImporter
Dim parser As NotesDOMParser
Dim node As NotesDOMDocumentNode
Dim nodelist As NotesDOMNodeList
Dim linknode As NotesDOMElementNode
Dim NodeParent As NotesDOMElementNode
Dim i As Long
Dim intCount As Integer
Dim DBUNID As String, ViewUNID As 
String, DocUNID As String, LinkText As String
Dim exportSucceeded As Boolean

Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc=dc.GetFirstDocument
Set exporter = session.CreateDXLExporter
Set parser = session.CreateDOMParser
 
Call exporter.SetInput(doc)
Call exporter.SetOutput(parser)
exporter.ExitOnFirstFatalError = False
exportSucceeded = False
Call exporter.Process
exportSucceeded = True
Set node = parser.Document
Set nodelist = 
node.GetElementsByTagName("doclink")
If nodelist.NumberOfEntries <> 0 Then
For i = 1 To nodelist.NumberOfEntries
Set linknode = nodelist.GetItem(i)
DBUNID = linknode.GetAttribute("database") 
ViewUNID = linknode.GetAttribute("view") 
DocUNID = linknode.GetAttribute("document") 
'get the text info for that link
Set NodeParent = linknode.parentnode
LinkText = nodeParent.GetAttribute("alttext") 
'make sure the link is still valid
  
  '...
'code to validate links can be 
used here, or create Link Info document... your call
 '...
Next
End If 
 
 
End Sub

One neat thing I added in this database is the option of having two embedded views: one showing doclinks in the current document, the other one showing links pointing to the current document. You should embed the view in the document's form and put the doc UNID as single category.

Do you have comments on this tip? Let us know.

Related information from SearchDomino.com:

  • FAQ: LotusScript advice
  • Learning Guide: LotusScript
  • Tip: Creating doclinks using undocumented LotusScript method
  • Reference Center: LotusScript tips and resources

    This tip was submitted to the SearchDomino.com tip library by member Benoit Dubuc. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

    Rate this Tip
    To rate tips, you must be a member of SearchDomino.com.
    Register now to start rating these tips. Log in if you are already a member.




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


    RELATED CONTENT
    LotusScript
    Launch large attachments within an email from a Notes database
    How to find files on a hard drive or mapped network with LotusScript
    Update the ACL from the Roles view with LotusScript
    LotusScript agent moves tagged spam email to junk mail folder
    Set a value in a field existing in another Lotus Notes database
    Create an automatic scheduled view export in Excel
    Top 10 LotusScript tips
    Create a personalized greeting for Lotus Notes database users
    Fail-safe rich-text validation using LotusScript
    How to export Lotus Notes views to a Microsoft Excel database

    Lotus Notes Domino Database Management
    Add a program doc to compact Lotus Notes databases automatically
    Set a value in a field existing in another Lotus Notes database
    Fix 'Audit Trail' error when opening Notes docs
    'Illegal circular use: Audit Trail' error when opening Lotus Notes docs
    Shrink Lotus Notes databases with many attachments
    Remove orphaned Lotus Notes documents on Domino databases with a 'virtual delete'
    Copy Lotus Notes databases from the Domino Server console command line
    Tutorial: How to import data into Lotus Notes -- without programming
    Easily show and hide layers in a Lotus Notes database
    Moving a remote user mail database to new Lotus Domino server

    LotusScript
    Launch large attachments within an email from a Notes database
    How to find files on a hard drive or mapped network with LotusScript
    Update the ACL from the Roles view with LotusScript
    LotusScript agent moves tagged spam email to junk mail folder
    Create a personalized greeting for Lotus Notes database users
    Fail-safe rich-text validation using LotusScript
    How to export Lotus Notes views to a Microsoft Excel database
    Create file system labels for Microsoft Excel and Word mail merges
    Fix Lotus Notes 8.0 issues when launching Microsoft Office applications
    Capture rich-text comments in Lotus Notes fields using LotusScript

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

  • HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




    All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts