About This Code
Brief Description:
Change any Location document field for all clients
Contributor:
Marko Bonaci
Notes Version:
R6.x, R8.x, R5.x, R7.x
Last Modified:
06 Jul 2009
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
Sub SetLocationItem( itemname As String, itemvalue As Variant )
'MbĪ, 14.02.2005.
'This procedure sets an item "itemname" to value itemvalue in the current user's location doc
Dim session As New notessession
Dim PrivateAddressBook As notesdatabase
Dim CurrentLocation As notesdocument
Dim LocationString As String, strTemp As String, LocationID As String
'Set PrivateAddressBook = New Notesdatabase( "", "names.nsf" )
Set PrivateAddressBook = GetLocalNAB()
If PrivateAddressBook Is Nothing Then
Print "Cannot get your local address book."
Exit Sub
End If
LocationString = Session.GetEnvironmentString( "Location", True )
If LocationString <> "" Then
strTemp = Mid( LocationString, ( Instr( 1, LocationString, "," ) + 1 ) )
LocationID = Left( strTemp, ( Instr( 1, strTemp, "," ) -1 ) )
Set CurrentLocation = PrivateAddressBook.GetDocumentByID( LocationID )
If Not CurrentLocation Is Nothing Then
Call CurrentLocation.ReplaceItemValue( itemname, itemvalue )
Call CurrentLocation.Save( True, False )
Call SendConfirmationEmail( )
Else
Msgbox |Unable to get current location document. Check notes.ini setting "Location".|
Exit Sub
End If
Else
Msgbox "Unable to get the location settings. Location setting in your notes.ini is empty."
Exit Sub
End If
End Sub
Function GetLocalNAB() As NotesDatabase
Dim session As New notessession
Dim sAddressBook As String
Dim nCommaLocation As Integer
On Error Resume Next
sAddressBook = session.GetEnvironmentString( "NAMES", True )
nCommaLocation = Instr( sAddressBook, "," )
If nCommaLocation > 0 Then sAddressBook = Left( sAddressBook, nCommaLocation - 1 )
Set GetLocalNAB = New NotesDatabase( "", sAddressBook )
End Function
Sub SendConfirmationEmail( )
Dim session As New notessession
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set doc = New NotesDocument( db )
doc.Form = "Memo"
doc.SendTo = "<Your Name or Name of admin who should receive confirmation that the values is successfuly changed for every client>"
doc.Subject = "Change succeded for " + session.CommonUserName
Call doc.Send( False )
End Sub
Usage / Example
I posted this on EE as a response to a LN beginner's question, so luckily, it's written in step-by-step instructions:
The main problem was how to push changes to all clients. I used e-mail with button in the body.
1. create new form
2. create new button on it
3. in button's (not form's) Options code section paste all three functions
4. then in buttons Click event type this (example for $SavedAddresses field):
Call SetLocationItem( "$SavedAddresses", "mbo.test.ok" )
To push the changes to clients, copy the button (in Designer, select it on the form then copy) and then paste it to new mail memo that you'll send to users, along with instructions.
I included mail sending code so you get e-mail confirming that the change has taken place (for each client).