Manage Learn to apply best practices and optimize your operations.

Remove saved computed-for-display values

Ever create a form with several computed-for-display fields -- but forget to define them as computed-for-display? This can result in duplicate data (wasting storage space) and improper display of information.

This agent -- which should be run on selected documents in a view or folder -- scrubs the data by removing all fields that begin with "disp", our standard naming convention for fields that are to be computed for display only (not saved in the document. This agent uses a case-insensitive comparison, so that fields beginning with "Disp", "DISP", or other variations would also be eliminated.

I like to use a two-line popup status bar when I run agents against a large set of documents, so I have included that option in my code; the user can decide whether or not to use it (stopping the agent in mid-run while the status bar is showing can cause Notes to "lock up", and there may be similar problems when trying to use the LotusScript debugger with the status bar displayed).

I believe I found the status bar functions and constant declarations in one of the TeamStudio templates (from Ives Development); the rest of the code is my own.

Option Public
Option Compare Nocase


Dim session As NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim collection As NotesDocumentCollection

Dim numToProcess As Long
Dim docCounter As Long
Dim numChanged As Long

Dim continue As Variant
Dim removedField As Variant

Dim logMsg As String

' For status bar display
Const NPB_TWOLINE%   = 1

Dim hwnd As Long

Declare Function NEMProgressBegin Lib "nnotesws.dll" ( Byval wFlags As
Integer ) As Long
Declare Sub NEMProgressEnd Lib "nnotesws.dll" ( Byval hwnd As Long )
Declare Sub NEMProgressSetBarPos Lib "nnotesws.dll" ( Byval hwnd As Long, Byval
dwPos As Long)
Declare Sub NEMProgressSetBarRange Lib "nnotesws.dll" ( Byval hwnd As Long,
Byval dwMax As Long )
Declare Sub NEMProgressSetText Lib "nnotesws.dll" ( Byval hwnd As Long, Byval
pcszLine1 As String, Byval pcszLine2 As String )

Dim UsingStatusBar As Variant

' Here we go... the main code....
Sub Initialize
	Dim msg2$
	Set session = New NotesSession
	Set db = session.CurrentDatabase
	Set collection = db.UnprocessedDocuments
	numToProcess = collection.count
	If numToProcess = 0 Then
		Messagebox "You have not selected any documents; none
updated.", MB_ICONEXCLAMATION, "Error"
		Exit Sub
		continue = Messagebox("Run on the " + Cstr(numToProcess) + "
 documents selected?", MB_YESNO + MB_ICONQUESTION, "Continue?")
		If continue <≶ IDYES Then
			Exit Sub
		End If
		userResp = Messagebox("Use status bar?",  MB_YESNO +
 MB_ICONQUESTION, "Debugging option")
		If userResp = IDYES Then
			UsingStatusBar = True 
			UsingStatusBar = False
		End If
		If UsingStatusBar Then
			hwnd = NEMProgressBegin(NPB_TWOLINE)
	  	        NEMProgressSetBarRange hwnd, numToProcess
			' Display the text specified by the user
                        NemProgressSetText hwnd, "Processing", ""
		End If
	End If
	docCounter = 0
	Set doc = collection.GetFirstDocument
	Do While Not (doc Is Nothing)
		docCounter = docCounter + 1
		msg2$ = Str$(docCounter) + " of " + Str$(numToProcess)
		If UsingStatusBar Then
			NEMProgressSetBarPos hwnd, docCounter
			NEMProgressSetText hwnd, "Removing display fields
 from", msg2$
		End If
		removedField = False
		Forall item In doc.Items
			If ( item.Name Like "disp*") Then
				Call item.Remove
				removedField = True
			End If
		End Forall
		If removedField Then
			numChanged = numChanged + 1
			Call True, False)
		End If
		Set doc = collection.GetNextDocument(doc)
	If UsingStatusBar Then
		NEMProgressEnd hwnd
	End If
	logMsg = "Processed " + Cstr(docCounter) + " of " + Cstr(numToProcess)
 + _
	" documents; removed display fields from " + Cstr(numChanged) + " of
	Messagebox logMsg
End Sub

Dig Deeper on Domino Resources - Part 6

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • 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 ...