LS Guru's- -Personal address book replace design script --LS included

During the process of upgrading 5.0.10 clients to 6.5.2, the personal address book has not been upgraded. Most users still have the version 5 design. I wrote some LS to run a convert on the address book depending on the users current Notes client version. If they are currently using the Version 5 client the script exits and does nothing. If the template version of the address book starts with 6.5 it does nothing. If the template vers of the nab does not start with 6.5 and the user has the 6 client, I want to run the nconvert on the address book.

The version 6 template is in the users program directory where it belongs. I think the old address book was being copied over after the 6 client was installed. Running a replace design fixes the issue but I do not want to involve the end users for apparent reasons.

Here are the two issues I am having:

User that have been upgraded to 6.5.2 that stiil have the Version5 address book do not have a $TemplateBuild. It is blank if you look in the names.nsf properties. When the script runs it does not do anything because it does not find it.

QUESTION 1.How can I determine if it is blank and run the convert.

QUESTION 2. The nconvert runs fine for me as I am an admin and developer with rights on the server and admin right on my PC. It seems that when the NCONVERT.exe is started via the Shell in the script, the user is prompted for a password and it does not run. What do I need to do to get the nconvert to run withour any user intervention.

I am putting this script into the iNotes6 template in a queryopen on a custom form that starts when the client is open.

I have searched the forum for two days looking for a solution to these 2 questions with no avail.

I did find a C API script but I am not familiar with the C API and I could not get it to work.

Please help

Thanks in advance…

Jerry

Dim session As NotesSession

Dim db As NotesDatabase ' for personal address book

Dim db2 As NotesDatabase ' for mailfile

Dim nc As NotesNoteCollection

Dim doc As NotesDocument

Dim iCount As Integer

Dim sNoteID As String



Const ITEM_BUILD_NAME = "$TemplateBuild"

Const ITEM_BUILD_DATE = "$TemplateBuildDate"

'get name and address book data

Set session = New NotesSession

Set db = session.GetDatabase("", "names")

Set db2 =session.CurrentDatabase

Set nc = db.CreateNoteCollection(False)

'get mailfile data

'If you are using client version 5.x exit

version1= Cstr(session.NotesVersion)

version2 =Strright(version1, " ")

version =Strleft(version2 , "|")

'Msgbox "Your current notes version is " & version

If Left(version ,1) ="5" Then

	Exit Sub

End If



'compare the template version of the names.nsf to target version

If Not nc Is Nothing Then

	nc.SelectSharedFields = True

	Call nc.BuildCollection

	

	sNoteID = nc.GetFirstNoteId

	For iCount = 1 To nc.Count

		Set doc = db.GetDocumentByID(sNoteID)

		If Not doc Is Nothing Then

			If doc.HasItem(ITEM_BUILD_NAME) Then

				stemp1 =Cstr(doc.GetItemValue(ITEM_BUILD_NAME)(0)) 'Get a string of the version number so you can compare it

'				Print "nab version" & stemp1

				stemp =Left(stemp1 , 3)

'				Print "nab version first 3 compare" & stemp

				same =Strcompare (stemp , "6.5"  ,5 ) ' Compare the current to the target

'				Print "compare result " & same					

				If same=0 Then 'If you have the same version as the target do not do anything

					Print "Address book and Client are equal"

					Exit Sub

				End If

'If you do not have the target version then prompt the user

				Print "Your Current Address Book Template Version is: " & doc.GetItemValue(ITEM_BUILD_NAME)(0)

				Print "Replacing the design of  your personal address book to Version 6"

				'Msgbox "If a black DOS screen appears prompting you for your Lotus Notes password, enter the password and click OK"

'This is where you put the executable to the nconvert.exe file

				Dim result As Integer

				'result = Shell("C:\Program Files\lotus\notes\nconvert.exe names.nsf * pernames.ntf", 1)

				result = Shell("nconvert.exe names.nsf * pernames.ntf", 6)

				If result <>33 Then ' Check to see if it ran OK

					Msgbox "Your Personal Name and Address book is not using the correct template. Please contact the help desk at 724-539-5226 to perform a replace design on your personal address book"

				Else

					Print "Your Personal Address book has been updated, Thank You"

				End If

'Msgbox "Date: " & doc.GetItemValue(ITEM_BUILD_DATE)(0) can use this to check the date

				Exit For

			End If

		End If

		sNoteID = nc.GetNextNoteID(sNoteID)

	Next iCount

End If	

End Sub

Subject: LS Guru’s- -Personal address book replace design script --LS included

I got rid of the error. When I try running this on a pc with the old address book, it is not finding the pernames template. The pernames is in the Documents and Settings\All Users\Lotus\Notes\Shared folder and not the users data directory. Is this the problem?

Subject: RE: LS Guru’s- -Personal address book replace design script --LS included

I would suggest to put the pernames.ntf on a Notes server and then reference it in your code

Call ReplaceDesign(“CN=Server name/O=Domain”, “pernames.ntf”,“”, “names55.nsf”, False)

JYR

Subject: RE: LS Guru’s- -Personal address book replace design script --LS included

JY,

Thanks so much for your help, eveything seems to be working OK but I have one more question. Is this going to run everytime the user logs in? Do I have to set an envoromnet var for this to only run once?

Subject: RE: LS Guru’s- -Personal address book replace design script --LS included

You can put a flag in the notes.ini:

'Check

If Session.GetEnvironmentString(“UpdateNames”) = “Yes” Then

Call ReplaceDesign(“CN=Server/O=Domain”, “pernames.ntf”,“”, “names.nsf”, False)

Call session.SetEnvironmentVar(“UpdateNames”, “Yes”)

 Print "Operation completed"

Else

Print "Already done"

End If

It will prevent your user to run the code every times

Subject: RE: LS Guru’s- -Personal address book replace design script --LS included

Many thanks for all your help. I just tested this on 5 and 6 clients and everything seems to be working. I modified the Intialization to chekc for the 5 client and update the ini.

Thanks again for all your help!!!

Sub Initialize

Dim session As New notessession

Set session = New NotesSession

'get mailfile data

version1= Cstr(session.NotesVersion)

version2 =Strright(version1, " ")

version =Strleft(version2 , "|")

'If you are using client version 5.x exit

If Left(version ,1) ="5" Then

	Print "Version 5"		

	Exit Sub

Else

'Check for notes.ini nabver variable

	Dim UpNab As String

	UpNab = session.GetEnvironmentString("NABVER")

	If UpNab ="YES" Then

		Print "NAB OK"

		Exit Sub

	Else	

		Call ReplaceDesign("naadmin01/srv/kmt", "pernames.ntf","", "names.nsf", False)

	End If

End If

End Sub

Subject: LS Guru’s- -Personal address book replace design script --LS included

Try this

Const DBCLASS_BY_EXTENSION = 0

Declare Function apiNSFDbOpen Lib “nnotes.dll” Alias “NSFDbOpen” (Byval filename As String, hDB As Long) As Integer

Declare Function apiNSFDbClose Lib “nnotes.dll” Alias “NSFDbClose” (Byval hDB As Long) As Integer

Declare Function apiDesignReplace Lib “nnotes.dll” Alias “DesignReplace”_

(Byval ht As Long, Byval hDB As Long, Byval dw1 As Long, Byval dw2 As Long, Byval dw3 As Long, Byval dw4 As Long) As Integer

Declare Function apiNSFDbCreate Lib “nnotes.dll” Alias “NSFDbCreate” (Byval PathName As String, Byval DbClass As Integer, Byval ForceCreation As Integer) As Integer

Dim source As String

Dim target As String

Dim htemplate As Long

Dim htarget As Long

Dim status As Integer

Sub Initialize

Call 	ReplaceDesign("CN=SOURCE SERVER/O=DOMAIN", "pernames.ntf","", "names.nsf", False)

End Sub

Function ReplaceDesign(Byval templateServer As String, Byval templateDB As String, Byval targetServer As String, Byval targetDB As String, Byval Createifneed As Variant) As Variant

ReplaceDesign = False



If templateServer = "" Then

	status = apiNSFDbOpen(templateDB, htemplate)

Else

	status = apiNSFDbOpen(templateServer & "!!" & templateDB, htemplate)

End If

If status<>0 Then

	Print "Can't open template."

	Exit Function

End If



If targetServer = "" Then

	status = apiNSFDbOpen(targetDB, htarget)

Else

	status = apiNSFDbOpen(targetServer & "!!" & targetDB, htarget)

End If

If staus<>0 And Createifneed Then 

	Print "Can't open database. Creating new."

	If targetServer = "" Then

		Call apiNSFDbCreate(targetDB, DBCLASS_BY_EXTENSION, True)

		status = apiNSFDbOpen(targetDB, htarget)

	Else

		Call apiNSFDbCreate(targetServer & "!!" & targetDB, DBCLASS_BY_EXTENSION, True)

		status = apiNSFDbOpen(targetServer & "!!" & targetDB, htarget)

	End If

End If

If status<>0 Then

	Print "Can't open database."

	Call apiNSFDbClose(htemplate)

	Exit Function

End If



Call apiDesignReplace(htemplate, htarget, 1, 1, 0, 0)

ReplaceDesign = True



Call apiNSFDbClose(htemplate)

Call apiNSFDbClose(htarget)

End Function

Subject: RE: LS Guru’s- -Personal address book replace design script --LS included

Trying now, I will let you know what happens.

Subject: LS Guru’s- -Personal address book replace design script --LS included

I copied and pasted your API into the QueryOpen event and I get the following error when compiling:Type mismatch on HTARGET.