Deleting private views when shared version changes

I have some working code that I got from this forum for deleting private views. I would like to enhance it so it only deletes the private views when the shared copy changes. I did some digging and as far as I can tell to accomplish this I think I need to use NIFFindView. When I try to use it I get “external function not found”. Here is the full text of my script, the parts dealing with comparing the private and shared views is commented out.

Am I going about this the right way? Is there a more effective way of accomplishing the same thing?

Thanks,

Charles

(Declarations)

Dim g_DeletedUNIDs() As String

Const APIModule = “nnotes.dll” ’ Windows/32 only

Const NOTE_CLASS_VIEW= &H0008

Declare Function OSPathNetConstruct Lib APIModule Alias “OSPathNetConstruct” _

( Byval NullPort As Long, Byval Server As String, Byval FIle As String, Byval PathNet As String) As Integer

Declare Function NSFDbOpen Lib APIModule Alias “NSFDbOpen” _

( Byval PathName As String, DbHandle As Long) As Integer

Declare Function NSFDbClose Lib APIModule Alias “NSFDbClose” _

( Byval DbHandle As Long) As Integer

Declare Function NIFFindPrivateDesignNote Lib APIModule Alias “NIFFindPrivateDesignNote” _

( Byval hdb As Long, Byval NoteName As String, Byval NoteClass As Integer, NoteID As Long ) As Integer

Declare Function NIFFindView Lib APIModule _

( Byval hdb As Long, Byval NoteName As String, NoteID As Long ) As Integer

Sub DeletePrivateView(db As NotesDatabase, vname As String)

’ To open a Domino database on a server, use this function to create

’ the full path specification, and pass this specification as input to NSFDbOpen

’ or NSFDbOpenExtended.

Dim p As String	

p$ = String(1024, " ")

OSPathNetConstruct 0, db.Server, db.FilePath, p$

’ This function takes a pathname to an existing Domino database or database

’ template (whether on a Lotus Domino Server or a local database), opens the

’ database, and returns a handle to it. All subsequent access to the database is

’ carried out via this handle. Use NSFDbClose to close the database file handle

’ and deallocate the memory associated with it.

Dim hDB As Long

NSFDbOpen p$, hDB

’ Given the name and NOTE_CLASS_xxx of a private design note (form, view,

’ folder, helpindex, macro, field, or replication formula ), this function returns the note ID.

’ Uses the View or Folder name passed to it - vname.

Dim retNoteID As Long

Dim result As Integer

result = NIFFindPrivateDesignNote(hDB, vname, NOTE_CLASS_VIEW, retNoteID)

'If result is anything other than 0, the Private Design Note could not be found

If result = 0 Then

	Dim privateview As NotesDocument

	Dim publicview As NotesDocument

	

	' Get the Private View or Folder by its NoteID

	Set privateview = db.GetDocumentByID( Hex$(retNoteID) )

	

	'Get the Public View or Folder by its NoteID

'***************

'*** This line gives the "external function not found message ***

'***************

	'result = NIFFindView(hDB, vName, retNoteID)

	'Set publicview = db.GetDocumentByID(Hex$(retNoteID))

	

	'Only delete the private view if it is older than the public view

	'Dim privatedate As NotesDateTime

	'Dim publicdate As NotesDateTime

	

	'Set privatedate = New NotesDateTime(privateview.LastModified)

	'Set publicdate = New NotesDateTime(publicview.LastModified)

	

	'If privatedate.TimeDifference(publicdate) < 0 Then

	Call privateview.Remove( True )

	Print "Removing : " & vname

'	Else

'		Print vname & " is current"

'	End If

Else

	Print "Could not find " & vname

End If

’ This function closes a previously opened database.

NSFDbClose hDB

End Sub

Subject: deleting private views when shared version changes

Hi Charles -

Try using W32NIFFindDesignNoteExt instead (see below). It’s a real function whereas NIFFindView is a C macro and as such, is unavailable to us lowly LotusScript writers. I’m not quite clear as to whether you’re trying to get a handle to the design note of the private view or the shared view. And what do you want to do after obtaining a handle to it? Look at the date modified I suppose? Is there some reason why you can’t use the NotesNoteCollection?

dgg

Declare Function W32OSPathNetConstruct Lib “nnotes” Alias “OSPathNetConstruct” ( _

Byval nullPort As Long, _

Byval serverName As Lmbcs String, _

Byval filePath As Lmbcs String, _

Byval pathNet As Lmbcs String _

) As Integer

Declare Function W32NSFDbOpen Lib “nnotes” Alias “NSFDbOpen” ( _

Byval dbPath As Lmbcs String, _

hDb As Long _

) As Integer

Declare Function W32NSFDbClose Lib “nnotes” Alias “NSFDbClose” ( _

Byval hDb As Long _

) As Integer

Declare Function W32NIFFindDesignNoteExt Lib “nnotes” Alias “NIFFindDesignNoteExt” ( _

Byval hDb As Long, _

Byval noteName As Lmbcs String, _

Byval noteClass As Integer, _

Byval flagPattern As Lmbcs String, _

retNoteID As Long, _

findOptions As Long _

) As Integer

Declare Private Function W32OSLoadString Lib “nnotes” Alias “OSLoadString” (_

Byval hModule As Long, _

Byval stringCode As Integer, _

Byval retBuffer As Lmbcs String, _

bufferLength As Integer _

) As Integer

Sub main()

On Error Goto errorHandler



Const NOTE_CLASS_VIEW = &H0008

Const DFLAGPATTERN_VIEWS_AND_FOLDERS_DESIGN = "-G40" '// see stdnames.h

’ Const DFLAGPAT_VIEWS = “-FG40n”

Const PATTERN = DFLAGPATTERN_VIEWS_AND_FOLDERS_DESIGN '// may need to change this depending on what you're doing

Dim nsess As NotesSession

Dim ndbSrc As NotesDatabase

Dim docDznNote As NotesDocument

Dim lngHDb As Long

Dim lngNoteID As Long

Dim intRC As Integer

Dim strViewName As String

Dim strPath As String * 512



Set nsess = New NotesSession()

Set ndbSrc = nsess.CurrentDatabase

strViewName$ = "All Documents"

'// Construct an API-friendly database path

Call W32OSPathNetConstruct(0&, ndbSrc.Server, ndbSrc.FilePath, strPath$)

'// Get a handle to the database

intRC% = W32NSFDbOpen(strPath$, lngHDb&)

If Not(intRC% = 0) Then

	Msgbox {Failed to obtain a handle to the target database - unable to continue.}, , "Failed to obtain a handle . . ."

	Goto subExit

End If

'// Get a the Note ID of the target view

intRC% = W32NIFFindDesignNoteExt(lngHDb&, strViewName$, NOTE_CLASS_VIEW, PATTERN, lngNoteID&, 0&)

If Not(intRC% = 0) Then '// this may be ok depending on what you're trying to do

	Msgbox {Failed to obtain a handle to the target view (} & strViewName$ & {) - unable to continue.}, , "Failed to obtain a handle . . ."

	Goto subExit

End If



Set docDznNote = ndbSrc.GetDocumentByID(Hex$(lngNoteID&))

'// We should now have a LS handle to the design note.

'// But we could also have gotten it "natively"via the NotesNoteCollection class, right?

subExit:

If lngHDb& > 0 Then

	Call W32NSFDbClose(lngHDb&) '// always try to close the db handle

	lngHDb& = 0

End If

Exit Sub

errorHandler:

'// This is just “generic” error-handling.

Msgbox "Error " & Err & ": " & Error$ & " encountered at line " & Erl & " of " & Getthreadinfo(1) & ".", , "Error encountered . . ."

Print "Error " & Err & ": " & Error$ & " encountered at line " & Erl & " of " & Getthreadinfo(1) & " . . ."

Resume subExit

End Sub

Subject: RE: deleting private views when shared version changes

Thanks Dallas, I’ll take a look through this and see what I can extract. Basically I just want to compare the LastModified date of the shared view with the LastModified date of the current user’s private copy. If they don’t match, the private copy is deleted.

I’ve never heard of a NotesNoteCollection, I’ll look that up and see if it will do what I need.

Thanks again,

Charles

Subject: deleting private views when shared version changes

I don’t see why you should have to resort to the API to do this. Why not just loop through the views in Lotusscript, and grab the modified dates of the private and public versions, and delete the private view if the two differ? Put that in the database script somewhere.