Simple code for location doc update

first of all I’m not a programmer so please be patient with me, I have need to update location document for all users, I found following piece of code:

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”, “onlinelocation”)

Call doc.FieldSetText(“MailType”, “Local”)

Call doc.FieldSetText(“ReplicationEnabled”, “1”)

Call doc.FieldSetText(“Enabled”, “1”)

Call doc.Save

Call doc.Close

End Sub

which does almost what I need to do but here is what I’m looking for I need to update existing document if one exist rather then create new location doc, above does not check and update but create duplicates, can someone modify this for me so if there is “onlinelocation” code will update rather then create duplicate

TIA

T.

Subject: re: simple code for location doc update

Give this a try:

Sub Click(Source As Button)

Dim workspace As New NotesUIWorkspace, session As New notessession

Dim doc As NotesUIDocument, qdoc As notesdocument, db As notesdatabase

Dim view As notesview, viewcoll As notesviewentrycollection

x=0

y=0

z=0

Set db = session.getdatabase("","names.nsf")

Set view = db.GetView("Locations")

Set viewcoll = view.allEntries



'if no location docs then create one

If viewcoll.count = 0 Then

	Goto nxt

End If



Set qdoc=view.GetFirstDocument

While Not qdoc Is Nothing

	If y=viewcoll.count Then Goto theEnd

	If qdoc.Name(0)="onlinelocation" Then

		'update the entry

		qdoc.LocationType="Local Area Network"

		qdoc.MailType="Local"

		qdoc.ReplicationEnabled="1"

		qdoc.Enabled="1"

		Call qdoc.Save(True,True)

		z=z+1

	End If

	Set qdoc=view.GetNextDocument(qdoc)

	y=y+1

Wend



'if no existing found then create one

If z=0 Then

	Goto nxt

Else 'end

	Goto theEnd

End If

nxt:

'Create location document

x=x+1

Call workspace.ComposeDocument( "", "names.nsf", "Location" )

Set doc = workspace.Currentdocument

Call doc.FieldSetText("LocationType", "Local Area Network")

Call doc.FieldSetText("Name", "onlinelocation")

Call doc.FieldSetText("MailType", "Local")

Call doc.FieldSetText("ReplicationEnabled", "1")

Call doc.FieldSetText("Enabled", "1")

Call doc.Save

Call doc.Close 

theEnd:

Msgbox "Agent ran and checked a total of "+Cstr(y)+" location documents and found "+Cstr(z)+" existing entries and created "+Cstr(x)+" new entries"

End Sub

Geoff-

Subject: This is perfect one more question

is there way to add line where this code would elso fill in field “Internet Mail Address” in format: <first_name_initail><last_name>@domain.com ?i.e. for Joe Doe it would be jdoe@domain.com

base on mail file owner without hard coding it?

I assume it would be something like:

Call doc.FieldSetText(“ImailAddress”, “@domain.com”) but what variable to use in front of @

Subject: Checks the user’s mail server for their assigned internet address and adds it…

Sub Click(Source As Button) Dim workspace As New NotesUIWorkspace, session As New notessession

Dim doc As NotesUIDocument, qdoc As notesdocument, db As notesdatabase

Dim view As notesview, viewcoll As notesviewentrycollection

Dim serverName As NotesName, userName As notesname



x=0

y=0

z=0

Set db = session.getdatabase("","names.nsf")

Set view = db.GetView("Locations")

Set viewcoll = view.allEntries



'get current user's internet address from the server address book to add to location document

Dim nabdb As NotesDatabase

Dim nabView As NotesView

Dim nabDoc As NotesDocument



'server name

serverNamn=Evaluate("@MailDbName")

'current user's name

userNamn=Evaluate("@UserName")

Msgbox Cstr(serverNamn(0))

Msgbox Cstr(userNamn(0))



Set serverName = session.CreateName(Cstr(serverNamn(0)))

Set userName = session.CreateName(Cstr(userNamn(0)))

Msgbox Cstr(serverName.common)

Msgbox Cstr(userName.abbreviated)

Set nabDb=session.GetDatabase(Cstr(serverName.common),"names.nsf")

Set nabView=nabDb.GetView("$VIMPeople")

Set nabDoc=nabView.GetDocumentByKey(Cstr(userName.abbreviated))

If nabDoc Is Nothing Then

	Msgbox "You are either not in the server's address book or there is no connection to your assigned mail server.  Your internet address can not be retrieved!"

	End

Else

	inetAddy=nabDoc.InternetAddress(0)

End If



'if no location docs then create one

If viewcoll.count = 0 Then

	Goto nxt

End If



Set qdoc=view.GetFirstDocument

While Not qdoc Is Nothing

	If y=viewcoll.count Then Goto theEnd

	If qdoc.Name(0)="onlinelocation" Then

		'update the entry

		qdoc.LocationType="Local Area Network"

		qdoc.MailType="Local"

		qdoc.ReplicationEnabled="1"

		qdoc.Enabled="1"

		qdoc.ImailAddress=inetAddy

		Call qdoc.Save(True,True)

		z=z+1

	End If

	Set qdoc=view.GetNextDocument(qdoc)

	y=y+1

Wend



'if no existing found then create one

If z=0 Then

	Goto nxt

Else 'end

	Goto theEnd

End If

nxt:

'Create location document

x=x+1

Call workspace.ComposeDocument( "", "names.nsf", "Location" )

Set doc = workspace.Currentdocument

Call doc.FieldSetText("LocationType", "Local Area Network")

Call doc.FieldSetText("Name", "onlinelocation")

Call doc.FieldSetText("MailType", "Local")

Call doc.FieldSetText("ReplicationEnabled", "1")

Call doc.FieldSetText("Enabled", "1")

Call doc.FieldSetText("ImailAddress",inetAddy)

Call doc.Save

Call doc.Close 

theEnd:

Msgbox "Agent ran and checked "+Cstr(y)+" location documents and found "+Cstr(z)+" existing entries and created "+Cstr(x)+" entries"

End Sub

Subject: one more question

Thanks for your help again, I have one more question. So due to issues I described below where switching location after updating location click on mailfile icon does not go after Location document setting but rather how mail file replicas are stack on workspace I was wondering if you could help me one more time and modify this script to do folowing:1. delete this location if exist and then recreate it with new settings definied rather then update it.

I tested and if I do not have this location and run scrip all works, basically clicking mail file icon on side bar will go by mail file location doc but if the location was updated it will go after how icon are stack on workspace

TIA

Subject: Try this to remove found entry…

Try this to remove and recreate the entry:

Sub Click(Source As Button)

Dim workspace As New NotesUIWorkspace, session As New notessession

Dim doc As NotesUIDocument, qdoc As notesdocument, db As notesdatabase

Dim view As notesview, viewcoll As notesviewentrycollection

Dim serverName As NotesName, userName As notesname



x=0

y=0

z=0

Set db = session.getdatabase("","names.nsf")

Set view = db.GetView("Locations")

Set viewcoll = view.allEntries



'get current user's internet address from the server address book to add to location document

Dim nabdb As NotesDatabase

Dim nabView As NotesView

Dim nabDoc As NotesDocument



'server name

serverNamn=Evaluate("@MailDbName")

'current user's name

userNamn=Evaluate("@UserName")

Msgbox Cstr(serverNamn(0))

Msgbox Cstr(userNamn(0))



Set serverName = session.CreateName(Cstr(serverNamn(0)))

Set userName = session.CreateName(Cstr(userNamn(0)))

Msgbox Cstr(serverName.common)

Msgbox Cstr(userName.abbreviated)

Set nabDb=session.GetDatabase(Cstr(serverName.common),"names.nsf")

Set nabView=nabDb.GetView("$VIMPeople")

Set nabDoc=nabView.GetDocumentByKey(Cstr(userName.abbreviated))

If nabDoc Is Nothing Then

	Msgbox "You are either not in the server's address book or there is no connection to your assigned mail server.  Your internet address can not be retrieved!"

	End

Else

	inetAddy=nabDoc.InternetAddress(0)

End If



'if no location docs then create one

If viewcoll.count = 0 Then

	Goto nxt

End If



Set qdoc=view.GetFirstDocument

While Not qdoc Is Nothing

	If y=viewcoll.count Then Goto theEnd

	If qdoc.Name(0)="onlinelocation" Then

		'delete the entry

		z=z+1		

		Call qdoc.remove(True)

		Goto nxt

		

		'update the entry

		'qdoc.LocationType="Local Area Network"

		'qdoc.MailType="Local"

		'qdoc.ReplicationEnabled="1"

		'qdoc.Enabled="1"

		'qdoc.ImailAddress=inetAddy

		'Call qdoc.Save(True,True)

		

	End If

	Set qdoc=view.GetNextDocument(qdoc)

	y=y+1

Wend



'if no existing found then create one

If z=0 Then

	Goto nxt

Else 'end

	Goto theEnd

End If

nxt:

'Create location document

x=x+1

Call workspace.ComposeDocument( "", "names.nsf", "Location" )

Set doc = workspace.Currentdocument

Call doc.FieldSetText("LocationType", "Local Area Network")

Call doc.FieldSetText("Name", "onlinelocation")

Call doc.FieldSetText("MailType", "Local")

Call doc.FieldSetText("ReplicationEnabled", "1")

Call doc.FieldSetText("Enabled", "1")

Call doc.FieldSetText("ImailAddress",inetAddy)

Call doc.Save

Call doc.Close 

theEnd:

Msgbox "Agent ran and checked "+Cstr(y)+" location documents and found "+Cstr(z)+" existing entries and created "+Cstr(x)+" entries"

End Sub

Geoff-

Subject: You made my day Thank you!

Subject: issues

code is working as far as updating location docs Thanks but issue I’m having is that although Mail File location is pointing to Local everytime I close and reopen Notes or everytime I changed from one location to another on the workspace mail file square with description “on server” for icon representing mailfile is always on top not sure why. Even if I changed this by clicking on arrow in square right hsn upper corner and chnaged it to local so it is on top it will come back “on server” when I switch back and forth between locations.Does my description make sense what I see?

only way to permamently change this behaviour is to edit manually location changed something and re-save it

why?

Subject: update

by the way reason I’m mentioning this is beacuse as long mailfile square icon has “on server” on workspace other setting in location doc is ignored and clicking on mail file icon on side bar will open whatever on workspace not what’s in mail file location in location doc