Lotusscript button to create a Location document in names.nsf

Hi,

I need to create a script to create a document Location inside the names.nsf. I had already created a script for a connection document but right now I need for the location.

I have several Lotus Client and I want to standardize all the configurations.

I also need to create a special button to delete all the existing connections/location documents in the names.nsf personnal address book.

Many thanks,

Subject: Lotusscript button to create a Location document in names.nsf

I think this will delete all connections and locations:

Sub Click(Source As Button)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim nextdoc As NotesDocument

Dim destLocation As Variant

Dim allnabs As Variant

allnabs=session.addressbooks

Forall books In allnabs

'If The NAB Is Private, Than It Should Be Your Personal NAB

If books.isprivateaddressbook Then

  'Verify if The NAB is Open, If Not, Open it

    If Not(Books.isopen) Then

      Call Books.open("",books.filename)

    End If

  Set db = Books

  Set view = db.GetView("Connections")

  Set doc = view.GetFirstDocument

  'Delete all connection documents

  While Not doc Is Nothing

    Set nextdoc=view.GetNextDocument(doc)

    Call doc.Remove(True) 

    Set doc=nextdoc			

  Wend

  Set view = db.GetView("Locations")

  Set doc = view.GetFirstDocument

  'Delete all location documents

  While Not doc Is Nothing

    Set nextdoc=view.GetNextDocument(doc)

    Call doc.Remove(True) 

    Set doc=nextdoc			

  Wend

End If

End Forall

End Sub

Then this will build a new location document, make sure you fill in the code with all the fields you want to set:

Sub Click(Source As Button)

Dim workspace As New NotesUIWorkspace

Dim doc As NotesUIDocument

'Create location document

Call workspace.ComposeDocument( “”, “names.nsf”, “Location” )

Set doc = workspace.Currentdocument

Call doc.FieldSetText(“LocationType”, “Local Area Network”)

Call doc.FieldSetText(“Name”, “Name of Location”)

Call doc.FieldSetText(“ImailAddress”, “yourName@yourDomain.com”)

Set the rest of the fields you want to set in here before saving and closing the doc

Call doc.Save

Call doc.Close

End Sub

I use something similar to this and just email the button to whoever I need to click on it.

Subject: RE: Lotusscript button to create a Location document in names.nsf

Hi,

Many thanks for your help. However the 1st routine (one to delete Location) gives me the following error: “Cannot remove NotesDocument when instantiated by NotesUIDocument”. Here is the code I made:

Sub Click(Source As Button)

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

Dim session As New NotesSession

Dim view As NotesView

Dim doc As NotesDocument

Dim nextdoc As NotesDocument

Dim destLocation As Variant



Set view = db.GetView("Connections")

Set doc = view.GetFirstDocument

'Delete all connection documents

While Not doc Is Nothing

	Set nextdoc=view.GetNextDocument(doc)

	Call doc.Remove(True)

	Set doc=nextdoc

Wend

Set view = db.GetView("Locations")

Set doc = view.GetFirstDocument

'Delete all location documents

While Not doc Is Nothing

	Set nextdoc=view.GetNextDocument(doc)

	Call doc.Remove(True)

	Set doc=nextdoc

Wend

End Sub

Many thanks again.