Help with script please

I got this script from someone. I have this in the mail template in the post open. What I’m trying to accomplish is create one connection document. However, it doesn’t seem to be working right. It creates the same connection document every time the mail file is opened – so I now have about 20 of the same connection docs. How do I modify it so it checks for that particular connection doc. and if it doesn’t exist, it creates, if not it won’t create?Thanks in advance

Helen


Function setcon

Dim session As New NotesSession

Dim Username As New NotesName(session.UserName)

Dim empdb As New NotesDatabase("","names.nsf")

Dim conndoc As New NotesDocument(empdb)

Dim targetdb As New NotesDatabase("", "")

Dim dc As NotesDocumentCollection



Set dc = empdb.Search({(Form = "Connection" | Form = "local") & @UpperCase(@Name([Abbreviate];Destination)) = "MAILWEB1/XX/XX/US"},Nothing,0)

If dc.count = 0 Then

	Set conndoc = New Notesdocument(empdb)

	conndoc.form = "Connection"

	conndoc.ConnectionType = "0"

	conndoc.Destination = "CN=MAILWEB1/OU=XX/O=XX/C=US"

	conndoc.LanPortName = "TCPIP"

	conndoc.PortName = "TCPIP"

	conndoc.ConnectionLocation = "*"

	conndoc.OptionalNetworkAddress = "mailweb1.xxx.com"

	conndoc.PhoneNumber = "mailweb1.xxx.com"

	conndoc.ConnectionLocation = "*"

	conndoc.Type = "Connection"

	conndoc.Source="*"

	conndoc.ConnectionRecordFirst = "1"

	conndoc.ComputeWithForm False,False

	Call conndoc.Save( True, True )	

Else

	Set conndoc = dc.GetFirstDocument

	conndoc.ConnectionRecordFirst = "1"

	conndoc.Destination = "CN=MAILWEB1/OU=XX/O=XX/C=US"

	conndoc.ComputeWithForm False,False

	Call conndoc.Save( True, True )	

	

	

End If

End Function

Subject: Help with script please

Hi Helen.

I think that the Dim conndoc statement is the culprit here.

It is creating a new document every time the code is run and both if and else save the document. I would try changing the DIM statement to

Dim conndoc As NotesDocument

  1. The code after the Else clause seems to be superfluous. why do you need to save the document again if it already has the information you need? If you do not need this I would eliminate the Else clause entirely.

  2. Are you creating Conflict documents for some reason? Check for the presence of the Notesitem $Conflict

  3. You may be causing the multiplicate entries through the doc.Save method.

doc.save(true,true)

forces the doc to save and (maybe) create a response doc. I know the Lotus docs say that the second true is ignored if the first is set to force, but my experiences with nd6/7 indicates that this does not always hold true. Try .Save(true, false)

Hope this helps.

Subject: Help with script please

Helen,

The logic is already there:

Dim dc As NotesDocumentCollection

Set dc = empdb.Search({(Form = “Connection” | Form = “local”) & @UpperCase(@Name([Abbreviate];Destination)) = “MAILWEB1/XX/XX/US”},Nothing,0)

If dc.count = 0 Then…

If dc.count =0 then modify the search string so that it hits on the connection you’ve created.

Does it work any better if the local NAB is full text indexed?

The other way to do this would be to get a handle to the ‘Connections’ view in the local NAB something like this:

Dim vw as NotesView

Set vw = empdb.GetView(“Connections”)

Set dc = vw.GetAllDocumentsByKey(“MAILWEB1/XX/XX/US”)

If dc.Count = 0 Then…

You might check to see if starting a new line at ‘Set dc = …’ fixes the problem before getting further into it.

Good luck!

EdC