Get the template name from a database

July 18, 2006 – 4:49 pm

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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

1
2
3
4
5
6
Sub Click(Source As Button)
	Dim s As New NotesSession
	Dim db As NotesDatabase
	Set db = s.currentdatabase
	Msgbox getTemplate ( db )
End Sub

Related posts:

  1. Replication of this database is not permitted
  2. New XPages based Wiki template
  3. SnTT: Is database design hidden (Notes API Solution)
  4. IBM Blog Template – Syntax Highlighter for Lotus Script
  5. Differences between the IBM Lotus Domino 7.0.2 Blog Template and previous external versions

  1. 2 Responses to “Get the template name from a database”

  2. I like it, and very simple. :grin:

    By Chad Schelfhout on Jul 18, 2006

  3. 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

    By Manfred Dillmann on Jul 18, 2006

Sorry, comments for this entry are closed at this time.