Manage Learn to apply best practices and optimize your operations.

Delete All Unused Fields From Db And Clear Up Design Field List

This is an agent that deletes all document fields which don't show up in any
forms or subforms. This eliminates the need to write an agent which lists every
single unwanted field, like
FIELD goAway := @DeleteField;.

If you compact the database after running this agent, the unwanted fields also
disappear from the design list in views etc.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim usedFields() As String
Dim count As Integer
Dim index As Integer
Dim i As Integer
Dim found As Integer
Dim items As Variant

Set db = session.CurrentDatabase

'Get all the fields in the forms of this db

Redim usedFields(0)
usedFields(0) ="Form" 'don't delete the form field

Forall form In db.Forms
count = Ubound(form.Fields)
index = Ubound(usedFields)+1
Redim Preserve usedFields(index+count)

For i = 0 To count
usedFields(index+i) = form.Fields(i)
End Forall

Set collection = db.AllDocuments

'Run thru all docs and delete unused Fields

For i = 1 To collection.Count
Set doc = collection.GetNthDocument( i )

items = doc.Items
Forall item In items
found = False

Forall field In usedFields
If = field Then
found = True
Exit Forall
End If
End Forall

If Not(found) Then
Call item.Remove
End If
End Forall

Call doc.Save( False, True )

End Sub

Dig Deeper on Lotus Notes Domino Administration Tools



  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...