About This Code
Brief Description:
Restrict access to design elements using reader fields
Contributor:
Andrew Jones
Last Modified:
17 Jun 2002
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
I'm using the function <getNoteID> that I've posted previously. It is published at http://searchdomino.techtarget.com/tip/1,289483,sid4_gci550220,00.html#feedback. The function gets the NoteID of a design element that is referenced by name and type(e.g. "getUserInfo" - AGENT)
-----------------------------
Option Public
Declare Function NIFFindDesignNote Lib "nnotes.dll" (Byval hDb As Long, Byval noteName As Lmbcs String, Byval classType As Integer, hNote As Long) As Integer
Declare Function NSFDbOpen Lib "nnotes.dll" (Byval sDbName As Lmbcs String , hDb As Long) As Integer
Declare Function NSFDbClose Lib "nnotes.dll" (Byval hDb As Long) As Integer
Declare Function OSPathNetConstruct Lib "nnotes.dll" (Byval portName As Integer, Byval serverName As Lmbcs String, Byval fileName As Lmbcs String, Byval pathName As Lmbcs String) As Integer
Const MAXPATH = 256
Const NOTE_CLASS_FORM = 0004 ' form note
Const NOTE_CLASS_VIEW = 0008 ' view note
Const NOTE_CLASS_FILTER = 0512 ' filter note
Const NOTE_CLASS_FIELD = 1024 ' field note
Function getNoteID(Byval servername As String,Byval filename As String,Byval notename As String, Byval notetype As Integer) As Long
Dim hdb As Long
Dim hnote As Long
Dim pathname As String*MAXPATH
Dim result As Integer
'OSPathNetConstruct creates a full network path - pathname - specification for a Domino database file
Call OSPathNetConstruct(0, servername, filename, pathname)
'NSFDbOpen returns a handle - hdb - to a database - pathname -
result = NSFDbOpen(pathname, hdb)
If result <> 0 Then
Messagebox("Cannot open the database!")
getNoteID = -1
Goto endf
End If
'NIFFindDesignNote function returns the note ID of a form, view, shared folder, agent, or field note, given the name and NOTE_CLASS_xxx
result = NIFFindDesignNote(hdb, notename, notetype, hnote)
If result <> 0 Then
Messagebox("Cannot find the note!")
getNoteID = -1
Goto dbclose
End If
getNoteID = hnote
dbclose:
'NSFDbClose closes a previously opened database
result = NSFDbClose(hdb)
If result <> 0 Then
Messagebox("Cannot close the database!")
End If
endf:
End Function
-----------------------------------
The Sub is adding the reader field to the agent document
-----------------------------------
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim noteID As Long
Dim strNID As String
Dim servername, dbname, notename As String
servername="SEARCHDOMINO" ' "" for local
dbname="TIPS.NSF"
notetype = NOTE_CLASS_FILTER ' agent
notename = "getUserInfo"
Set db = s.GetDatabase(servername, dbname)
noteID = getNoteID(servername, dbname, notename, NOTE_CLASS_FILTER)
If noteID = -1 Then
Goto ends
End If
strNID = Hex(noteID)
Set doc = db.GetDocumentByID (strNID)
If (Not doc Is Nothing )Then
Dim newValues( 1 To 1 ) As String
newValues( 1 ) = "[admin]"
Dim readersItem As New NotesItem(doc, "docReaders", newValues, READERS)
Call doc.Save( True, True )
End If
ends:
End Sub
Usage / Example