Get the template name from a database

Here is a quick LotusScript tip on how to get the name of the template that is used for a specific database. The NotesDatabase Class has a method to determine the template name. But this only works for a template file itself ( template.ntf ) As far a I could find out, there is no method to grab the template name for a database.

I found out theat the name is stored in the NotesDatabase icon. The icon can be accessed as any other Notes document. From Release 6 on there is a new class called NotesNoteCollection class . The NotesNoteCollection class represents a collection of Domino design and data elements in a database.

I did a quick debug to find the proper place to look for the template name value. Well, here is the code.

Function getTemplate( db As NotesDatabase ) As String

	Dim template As String, aux As String
	Dim nc As NotesNoteCollection
	Dim icon As notesdocument
	Dim noteid As String

	getTemplate = ""
	Set nc = db.CreateNoteCollection( False )
	nc.SelectIcon = True
	Call nc.BuildCollection

	Set icon = db.GetDocumentByID( nc.GetFirstNoteId )

	If Not icon Is Nothing Then
		getTemplate = icon.Parentdatabase.DesigntemplateName
	End If

End Function

To test the code, put the funktion together with the following code into an action button in a view of your “sandbox” database

Sub Click(Source As Button)
	Dim s As New NotesSession
	Dim db As NotesDatabase
	Set db = s.currentdatabase
	Msgbox getTemplate ( db )
End Sub

2 thoughts on “Get the template name from a database

  1. Ulrich, maybe you have mixed-up the database properties “DesignTemplateName” and “TemplateName”? The second works only for a template file (.NTF).

    But “DesignTemplateName” works for me for a .NSF without problems. Try this code:

    Sub Click(Source As Button)
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Set db = s.currentdatabase
    Msgbox db.DesignTemplateName
    End Sub

    One other point. In your function “getTemplate” you are getting a handle to the DB-Icon-Note:

    Set icon = db.GetDocumentByID( nc.GetFirstNoteId )

    Later on you are using this “document” only to get a handle to the database itself and then use the database-property DesignTemplateName:

    getTemplate = icon.Parentdatabase.DesigntemplateName

    You are not accessing the field “$Title” which contains the db-title and template-name. So why are you accessing the icon-design-note at all?

    Regards, Manfred

Comments are closed.