Tip

Record User Activity On Access To Documents

View member feedback to this tip.

The 'User Activity' log in the 'database preferences' records when a user has read/written to a database. However, it doesn't list what documents the user has been opening/writing. This code records what documents a user has been reading/writing even if they have only 'Read' access in the ACL.

To implement on a database:
1. Create a Form in the database. ('Log' in the code)
2. In the form create two fields, one is the log data field, which should be
rich text (AccessLog in the code). The
other a date field. (LogDate in the Code)
3. Goto properties. In 'Golden Key' section, select 'Available to Public
Access Users'
4. Create a view in the database. ('LogView' in the code)
5. Selection formula is by the form you created (e.g. SELECT Form = "Log")
6. Add one column and set the data as @Created.
7. Cut and paste the code below into the form you want to record user activity
(in the terminate event of the form)
8. Update the Constants in the code to the Log form and view name.
9. Change the 'TitleField' constant to the identification field in the form
(i.e. when you read the log, it identifies the document)
10. Launch.
Sub Terminate
'Version : 1.02
'Function : Record all reads by any user of the database in a daily log (1
log per day)
'Author : Christopher Williamson/Development
'Date : 21/06/2000
'Method :
'Initialise Variables
'Get the user & form details
'Check if today's log exists
'If it does update it
'Else Create log and write details
'Save the doc
'End

'Change these vars to reqs
'The title field used to identify document in the log
Const TitleField = "Doc_Title_1"
'The view name for the log documents
Const LogViewName = "By Log"
'The date field of the log
Const LogDateField = "LogDate"
'The details field in the log (must be multivalue)
Const LogDetailsField = "AccessLog"
'The form name in the log
Const LogFormName = "Log"

Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim db As NotesDatabase
Dim udoc As NotesDocument
Dim doc As NotesDocument
Dim uidoc As NotesUIDocument
Dim newdoc As NotesDocument
Dim view As NotesView
Dim LogExists As Integer

'Lazy Error handler - this is only required if a user creates a doc then
cancels
On Error Resume Next

'Get the current doc
Set uidoc = workspace.currentdocument
Set udoc = uidoc.Document

'Get the reader name and current date & time
user = Evaluate("@Name([Abbreviate]; @UserName)")
dateread = Evaluate("@Now")
readstring = user(0)
readstringdate = dateread(0)
'The string that is written to the log.
displayall = readstring & " : " & readstringdate & " : " &
udoc.GetFirstItem("Form").text & " : " & udoc.GetFirstItem(TitleField).text &
Chr$(13)

'get the current log docs from the 'Log' view
Set view = Session.CurrentDatabase.GetView(LogViewName)
'get the last doc (reuse the doc var as it wont be used again)
Set doc = view.GetLastDocument
'loop thro logs and look for a log created today
Do While Not doc Is Nothing And Not LogExists
Set temp = doc.GetFirstItem(LogDateField)
If temp.text = Format(Date$,"dd/mm/yyyy") Then
LogExists = -1
Else
Set doc = View.GetPrevDocument(doc)
End If
Loop

'if doc already exists then update the field
If Not doc Is Nothing Then
Set item = doc.GetFirstItem(LogDetailsField)
Call item.AppendToTextList(displayall)
Call doc.Save(False,False)
Else
'create the doc
Set newdoc = session.currentdatabase.Createdocument
newdoc.form = LogFormName
'give all users access to write this log (although they don't have a
clue >:) )
Dim PublicAccess As New NotesItem(newdoc, "$PublicAccess","1")
'write the text to doc
Dim item2 As New NotesItem(newdoc, LogDetailsField, displayall)
'write the date to doc
Dim item3 As New NotesItem(newdoc,LogDateField, Format(Date$,
"dd/mm/yyyy"))
Call newdoc.Save(False,False)
End If
End Sub


MEMBER FEEDBACK TO THIS TIP

Can the code be put into Memo form to record e-mail activity, or does a form exist for All Documents so that all activity on a mail file can be recorded?

—Andrew W.

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

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.