Domino Code Fragment

Code Name*
Change a view name with LotusScript
Date*
6/26/97
Source (or email address if you prefer)*
Bill Ernest
IP address:.18.218.168.16
Description*
Use API routines exposed in Notes client DLLs to change the name of a view.
Type*
LotusScript
Categories*
Design Configuration
Implementation:
Modify constants
Required Client:
Server:
Limitations:
Works on Win95/98/NT as is, can be modified for UNIX. Does not work on Apple or OS/2.
Comments:
Paste this into a LotusScript button.

Note that you can use this to copy, rename, modify design elements. Useful for installation routines that add/remove design elements to existing databases.

You may need to close and re-open the db to see the new view name displayed.
Files/Graphics attachments (if applicable): Code:


Declare Sub OSPathNetConstruct Lib "nnotes.dll" (Byval portName As String, Byval ServerName As String, Byval FileName As String, Byval retPathName As String)
Declare Function NSFDbOpen Lib "nnotes.dll" (Byval PathName As String, dbHandle As Long) As Integer
Declare Function NSFDbClose Lib "nnotes.dll" (Byval dbHandle As Long) As Integer
Declare Function NSFNoteOpen Lib "nnotes.dll" (Byval dbHandle As Long, Byval noteID As Long,  Byval openFlag As Integer, retNoteHandle As Long) As Integer
Declare Function NSFNoteClose Lib "nnotes.dll" (Byval noteHandle As Long) As Integer
Declare Function NSFNoteUpdate Lib "nnotes.dll" (Byval noteHandle As Long, Byval openFlag As Integer ) As Integer
Declare Function NSFItemDelete Lib "nnotes.dll" (Byval noteHandle As Long, Byval itemViewTitle As String, Byval nameLen As Integer ) As Integer
Declare Function NSFItemSetText Lib "nnotes.dll" (Byval noteHandle As Long, Byval itemViewTitle As String, Byval newName As String, Byval nameLen As Integer ) As Integer
Declare Function NIFFindDesignNote Lib "nnotes.dll" (Byval dbHandle As Long, Byval designName As String, Byval designClass As Integer, retNoteID As Long) As Integer

Const NOTE_CLASS_DOCUMENT =  &H0001
Const NOTE_CLASS_DATA = NOTE_CLASS_DOCUMENT
Const NOTE_CLASS_INFO = &H0002
Const NOTE_CLASS_FORM = &H0004
Const NOTE_CLASS_VIEW = &H0008
Const NOTE_CLASS_ICON = &H0010
Const NOTE_CLASS_DESIGN = &H0020
Const NOTE_CLASS_ACL = &H0040
Const NOTE_CLASS_HELP_INDEX = &H0080
Const NOTE_CLASS_HELP = &H0100
Const NOTE_CLASS_FILTER = &H0200   'This is an Agent, Macro
Const NOTE_CLASS_FIELD = &H0400
Const NOTE_CLASS_REPLFORMULA = &H0800
Const NOTE_CLASS_PRIVATE = &H1000
Const NOTE_CLASS_DEFAULT = &H8000
Const NOTE_CLASS_NOTIFYDELETION = NOTE_CLASS_DEFAULT
Const NOTE_CLASS_ALL = &H7FFF
Const NOTE_CLASS_ALLNONDATA = &H7FFE
Const NOTE_CLASS_NONE = &H0000
Const VIEW_TITLE_ITEM = |$Title|


Dim dbHandle As Long
Dim noteHandle As Long
Dim status As Integer
Dim Path As String * 256
Dim NoteID As Long
Dim newName As String
Dim oldLen As Integer
Dim newLen As Integer



Function GetDesignIDStr(db As NotesDatabase, DesignName As String, DesignType As Integer) As String
   
    ' Set handles to NULL (to help in error handling)
    dbHandle = 0
    GetDesignIDStr = ""
   
    On Error Goto pError
   
    dbServer = db.Server
    dbFilePath = db.FilePath
    Call OSPathNetConstruct("", dbServer, dbFilePath, Path)
   
    Call NSFDbOpen( Path, dbHandle)
    If (dbHandle = 0) Then
         Error 1
         Goto pError
    End If
   
    Call NIFFindDesignNote(dbHandle, DesignName,  DesignType, NoteID)
    GetDesignIDStr = Hex$(NoteID)
   
    Call NSFNoteOpen( dbHandle, NoteID, 0, noteHandle)
    If (noteHandle = 0) Then
         Error 1
         Goto pError
    End If
   
    Goto alldone    
pError:
    Exit Function
   
alldone:
End Function


Sub UpdateViewTitle(dbHandle As Long, noteId As Long, viewTitle As String, newName As String, oldLen As Integer, newLen As Integer)
   
    ' Set handles to NULL (to help in error handling)
    noteHandle = 0
   
    On Error Goto pError
   
    Call NSFNoteOpen( dbHandle, NoteID, 0, noteHandle)
    If (noteHandle = 0) Then
         Error 1
         Goto pError
    End If
   
    itemdel% = NSFItemDelete( noteHandle, viewTitle, oldLen)
   
    itemset% =  NSFItemSetText( noteHandle, viewtitle, newName, newLen)
   
    updatenote% = NSFNoteUpdate(noteHandle, 0)
   
pError:
    Exit Sub
End Sub


Sub CloseThings (noteHandle As Long, dbHandle As Long)
    If(noteHandle <>0) Then
         Call NSFNoteClose(noteHandle)
    End If
    If (dbHandle <> 0) Then
         Call NSFDbClose(dbHandle)
    End If
End Sub


Sub Click(Source As Button)
    functionname = "View Naming"
    Call InitializeGlobals ( functionname )
    functionname = "initializeGlobals"
    viewalias$ = "CleanUp"
    newPubName = "XXX\FooBar"
    NoteIDStr = GetDesignIDStr(scfdb, viewalias$, NOTE_CLASS_VIEW)
    Messagebox("CleanUp NoteID = " + NoteIDStr)
    Set doc = scfdb.GetDocumentByID(NoteIDStr)
    u1 = doc.GetItemValue(VIEW_TITLE_ITEM)
    u1str$ = u1(0)
    oldLen = Len(u1str$ )
    orsign$ = "|"
    lenpub% = Instr(1, u1str$ , orsign$) -1
    lenalias% = oldLen-(lenpub%+1)
    publicName = Left(u1str$ , lenpub%)
    aliasName = Right(u1str$ , lenalias%)
    Messagebox("$Title = " + u1str$ )
    Messagebox("publicName  = " +publicName)
    Messagebox("aliasName = " + aliasName)
    newName =  newPubName + orsign$ + aliasName
    newLen = Len(newName)
    Messagebox("newName = " + newName)
   
    Call UpdateViewTitle(dbHandle, noteId, VIEW_TITLE_ITEM, newName, oldLen, newLen)
   
    Call CloseThings(noteHandle, dbHandle)

     
   
End Sub