OpenNTF.org - FieldDeleter
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
Edit Document Code By Date > Code Document
About This Code
Brief Description:
FieldDeleter 
Rating:
Rating: 5 , Number of votes: 1 
Contributor:
Tim Paque 
Category:
Lotusscript 
Type:
Utilities 
Document Release:
1.0 
Notes Version:
R4.x, R6.x, R8.x, R5.x, R7.x 
Last Modified:
09 Dec 2009 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
Deletes Selected Fields from Selected Documents



Option Public
Sub Initialize
Dim session As New notessession
Dim db As notesdatabase
Dim col As notesdocumentcollection
Dim doc As notesdocument
Dim uiWorkspace As New NotesUiWorkspace
Set db=session.currentdatabase
Set col=db.unprocesseddocuments
Set doc=col.getfirstdocument
Dim Fld As NotesItem
Dim FldCount As Integer
If db.currentaccesslevel < 5 Then ' Little Security Touch
Print ("Access Denied")
Beep
Beep
Beep
Beep
Beep
Beep
Beep
Exit Sub
End If

'Get list of field names
FldCount = 0
Forall item In doc.Items
FldCount = FldCount + 1
End Forall
Redim FieldList(0 To FldCount)
FieldList(0) = "-Unlisted Field-"
x=0
Forall item In doc.Items
x=x+1
FieldList(x) = Cstr(item.name) ' now FieldList is an array with all fieldnames
End Forall
Call Sort(FieldList) ' Now it's alphabetized

'Now to select which fields
FieldToChange = UIWorkspace.Prompt(PROMPT_OKCANCELLISTMULT, "---- Field Deleter ----", "Please select wich fields you wish to Delete.","" ,FieldList )
If Isscalar(FieldToChange) Then
Print "Canceled"
Exit Sub
End If
If FieldToChange(0) = "-Unlisted Field-" Then
FieldToChange(0) = UIWorkspace.Prompt(PROMPT_OKCANCELEDIT, "---- Field Deleter ----", "Enter the Field Name you wish to Delete","" )
If Trim(FieldToChange(0)) ="" Then
Print "Canceled"
Exit Sub
End If
End If


While Not doc Is Nothing
For y= Lbound(FieldToChange) To Ubound(FieldToChange)
If Cstr(FieldToChange(y)) <> "" Then
Set deadfield = doc.GetFirstItem(FieldToChange(y))
If Not deadfield Is Nothing Then Call deadfield.Remove
End If
Next

Call doc.save(False,False)
Set doc=col.getnextdocument(doc)
Wend
End Sub
Sub Sort(array)
n=Ubound(array)+1
For I=1 To (n-1)
J=I
Do While J>=1
If array(J)<array(J-1) Then
A=array(J)
A1=array(J-1)
array(J)=A1
array(J-1)=A
J=J-1
Else
Exit Do
End If
Loop
Next
End Sub

Usage / Example
Rebuilding an old database? and there are hundreds of Junk fields taking up space on the documents? (Like when a previous developer put four fields for each of the two hundred possible products you MIGHT sell?)

Once you are all done fishing out the useful data, use this utility to strip off the Junk!
Select the documents you wish to delete fields from, and select the fields you wish to remove!
 Comments

No documents found

 Add your comment!