Domino Code Fragment

Code Name*
Creating a Domino agent to count the number of hits on a web page
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.137.180.32
Description*
Creating a Domino agent to count the number of hits on a web page
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Using a Domino web server, is it possible to create a counter to keep track of how many times a particular web page has been accessed?

Solution:

By using the Domino Release 4.5 $$QueryOpenAgent field feature and LotusScript, you can create a counter to keep track of how many times a particular web page has been accessed. To implement this, follow these steps:

Sub Initialize
Dim Session As New NotesSession
Dim ProfileDoc As NotesDocument
Dim doc As NotesDocument
Dim num As Double
Dim NumStr As String


Set db = Session.CurrentDatabase

'The following line gets a handle to the current document
Set doc = Session.DocumentContext


'The following line creates a Profile document called 'Domino' the first time
'it is executed and from then on modifies the existing 'Domino' document
Set ProfileDoc = db.GetProfileDocument("Domino")


NumStr = ProfileDoc.num(0)
If NumStr = "" Then
num = 1
Else
num = Cdbl(NumStr) + 1
End If


ProfileDoc.num = Cstr(num)
Call profiledoc.save(False,False)


doc.Number = num

End Sub


On the form you wish to keep the counter on, create a number field named Number .
Also add a computed text field named $$QueryOpenAgent. As the formula for this field, put
in quotes whatever you named your agent (for example: "Counter").

After completing these three steps, your counter should be complete. From now on, whenever
a web uses accesses a document using this form, the counter will increment by one and display
the new value in the Number field.