Lotus Notes — рабочий инструмент программиста.

Обсуждения программирования на Lotus Notes/Domino

Archive for Ноябрь 15th, 2008

Delete BES State Databases

без комментариев

‘Options
Option Declare ‘ Declarations
‘%INCLUDE "LsConst.LSS"
‘ msgBoxOptions = MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2
Const msgBoxOptions = 4 + 32 + 256
‘ yes = IDYES
Const yes = 6 Sub Click(Source As Button)
‘ posted to http://www.openntf.org/projects/codebin/codebin.nsf/CodeByDate/3307822D17936284862575000058210D
‘ written by Mike Mortin, 20081015 Dim ui As New NotesUIWorkspace
Dim uidoc As NotesuiDocument
Dim db() As NotesDatabase
Dim user As String, serverList() As String, msg As String
Dim index As Long, numDbs As Long
Dim deleteDbs As Boolean ‘ set up
Set uidoc = ui.CurrentDocument
user = uidoc.FieldGetText("firstname") & " " & uidoc.FieldGetText("lastname")
deleteDbs = False ‘ get the server names
If 0 Then
‘ hard code the server names
Redim serverList(0 To 2)
serverList(0) = "BES01/SVR/CA"
serverList(1) = "BES02/SVR/CA"
serverList(2) = "BES03/SVR/CA"
Else
‘ load from a group
Dim s As New NotesSession
Dim doc As NotesDocument
Dim key(0) As Variant
key(0) = "BlackBerryServers" ‘ <– put the group name that contains your BlackBerry servers
Set doc = GetDocFromDb(s.CurrentDatabase, "Groups", key, True)
Redim serverList(Lbound(doc.Members) To Ubound(doc.Members))
For index = Lbound(doc.Members) To Ubound(doc.Members)
serverList(index) = doc.Members(index)
Next
End If ‘ grab each database
Redim db(Lbound(serverList) To Ubound(serverList))
For index = Lbound(serverList) To Ubound(serverList)
Set db(index) = GetDbByTitle(serverList(index), user)
If Not db(index) Is Nothing Then numDbs = numDbs + 1
Next If numDbs = 0 Then
‘ tell admin that there are no state dbs found
Messagebox("No State database for " & user & " were found.")
Else
If numDbs = 1 Then
‘ find the active Db
For index = Lbound(serverList) To Ubound(serverList)
If Not db(index) Is Nothing Then Exit For
Next ‘ let the admin know which server the db was found on and prompt to delete
msg = "State database for " & user & " only found on " & db(index).Server & ". Do you want to delete this file?"
Else
‘ prompt to delete all replicas
msg = "Are you sure you want to delete the " & numDbs & " state databases for " & user & "?"
End If If Messagebox(msg, msgBoxOptions) = yes Then deleteDbs = True
End If ‘ delete the dbs
If deleteDbs Then
For index = Lbound(serverList) To Ubound(serverList)
If Not db(index) Is Nothing Then db(index).Remove
Next
End If
End Sub Function GetDbByTitle(serverName As String,userName As String) As NotesDatabase
On Error Goto ExitSub
Dim server As NotesDbDirectory
Dim db1 As NotesDatabase, db2 As NotesDatabase ‘ Find db on server
Set server = New NotesDbDirectory(serverName)
Set db1 = server.GetFirstDatabase(DATABASE)
While Not (db1 Is Nothing)
If userName = db1.Title Then
If db2 Is Nothing Then
Set db2 = db1
Else
Msgbox "Duplicate db title found on "& serverName
Exit Function
End If
End If
Set db1 = server.GetNextDatabase
Wend ExitSub: Set GetDbByTitle = db2
Exit Function
End Function

Original source : http://www.openntf.org/projects/codebin/codebin.ns…

Написано lotusnotes

Ноябрь 15, 2008 в 8:03

Опубликовано в Lotus Notes

is application on local or not (function)

без комментариев

this function checks if the current application is on the server or local. true = is on local
false = is on a server Its a very small and easy function. But sometimes useful ;-)

Original source : http://www.openntf.org/projects/codebin/codebin.ns…

Написано lotusnotes

Ноябрь 15, 2008 в 8:03

Опубликовано в Lotus Notes

Open database listed in an email ( like GSX errors )

без комментариев

Sub Initialize
‘ posted to http://www.openntf.org/projects/codebin/codebin.nsf/CodeByDate/BB07663266C769D2862574F60054154B
‘ written by Mike Mortin, 20070830 Dim ws As New NotesUIWorkspace
Dim uiDoc As NotesUIDocument
Dim nServer As NotesName
Dim tempStr As String, fileList As String, server As String
Dim tempVar As Variant
Dim index As Integer
Const kDelim = " " ‘ get email content
Set uiDoc = ws.CurrentDocument
tempStr = uiDoc.FieldGetText("body") ‘ split and join to remove unwanted characters
tempVar = Split(tempStr, Chr(13)) ‘ new line characters
tempVar = Join(tempVar, kDelim)
tempVar = Split(tempVar, "’") ‘ single quotes
tempVar = Join(tempVar, kDelim) ‘ lastly, split into words
tempVar = Split(tempVar, kDelim) ‘ spaces ‘ server name is the next entry
Set nServer = New notesName(tempVar(3))
server = nServer.Common ‘ then parse through remaining entries to get all mailfiles listed
For index = Lbound(tempVar) To Ubound(tempVar)
Print tempVar(index)
If Instr( tempVar(index), ".nsf" ) > 0 Then
‘ add it to the list
tempStr = Left( tempVar(index), Instr( tempVar(index), "nsf") +2 )
fileList = fileList & tempStr & ","
End If
Next index ‘ now, did we find any mail files? If Len(fileList) > 0 Then
‘ make the list and tighen it up
tempVar = Split( fileList, "," )
tempVar = Arrayunique(tempVar)
tempVar = Fulltrim(tempVar) ‘ present and open the db
tempStr = ws.Prompt(4, "Select the database on " & server & " that you want to open.", "Click ‘Cancel’ to exit.", "", Split( fileList, "," ))
If tempStr <> "" Then Call ws.OpenDatabase(server, tempStr)
Else
Msgbox "No mailfiles detected"
End If
End Sub

Original source : http://www.openntf.org/projects/codebin/codebin.ns…

Написано lotusnotes

Ноябрь 15, 2008 в 8:03

Опубликовано в Lotus Notes

Clear the Recent Contacts

без комментариев

Here is a quick little code that I added to the R8 Mail template to quickly purge the Recent Contacts in R8. It removes the documents from the local NAB & clears the Metadata from the local PC.

Original source : http://www.openntf.org/projects/codebin/codebin.ns…

Написано lotusnotes

Ноябрь 15, 2008 в 8:03

Опубликовано в Lotus Notes

PromptMailTemplateUsed – Get information about the template your mail database inherits from.

без комментариев

[<pre>
Sub PromptMailTemplateUsed()
‘Written by John Smart John.Smart@GreyDuck.com
‘Submitted to OpenNTF on 30 Oct 2008
‘http://www.openntf.org/projects/codebin/codebin.nsf/CodeByDate/660570790A3B977B862574F2006E3E4F
Dim db As New NotesDatabase("", "")
Dim doc As NotesDocument
Dim strMsg As String
Dim strTemplateName As String
Dim strTemplateServerName As String
Dim strTemplateFileName As String Print "Finding your email database…"
Call db.OpenMail() Print "Verifying that your email database inherits from a template…"
strTemplateName = db.DesignTemplateName
If Len(strTemplateName) = 0 Then
Error 1000, "Your mail database doesn’t inherit it’s design from a template."
End If Print "Getting information about where your mail template inherits from…"
Set doc = db.GetDocumentByID("FFFF0010") ‘icon design element. Thanks to http://www.nsftools.com/tips/NotesTips.htm#defaultelements ‘Get template information stored in the icon design element. Thanks to http://www.notesninjas.com/#TemplateFileName
strTemplateServerName = doc.GetItemValue("$TemplateServerName")(0)
strTemplateFileName = doc.GetItemValue("$TemplateFileName")(0) strMsg = |Design Template Name: | + strTemplateName + |
Server: | + strTemplateServerName + |
File Path: | + strTemplateFileName + | NOTE: File Path is based on the server’s operating system, so a File Path of "/local/notes/data/mail8.ntf" would imply that your template is probably "mail8.ntf" in the root data directory on your server.| Print ""
Messagebox strMsg, 0, "Hints on where to find your mail template."
End Sub
</pre>]

Original source : http://www.openntf.org/projects/codebin/codebin.ns…

Написано lotusnotes

Ноябрь 15, 2008 в 8:02

Опубликовано в Lotus Notes

Modify or Remove any field in the current view

без комментариев

Sub Initialize
‘ from the current view, removes a field or modifies a field in every document
‘ posted to http://www.openntf.org/Projects/codebin/codebin.nsf/CodeBySubCategory/A37FAED4F7480160862574F10071BAAA
‘ written by Mike Mortin 20081029
On Error Goto ErrorHandler
Dim s As NotesSession
Dim ws As New NotesUIWorkspace
Dim currentDb As NotesDatabase
Dim uiView As NotesUIView
Dim view As NotesView
Dim coll As notesViewEntryCollection
Dim entry As NotesViewEntry
Dim doc As NotesDocument
Dim field As String, newValue As String, msg As String, action As String
Dim items As Variant
Const kActionRemove = "remove"
Const kActionReplace = "replace"
Const kActionNone = ""
Const kMsgNoActionDone = "No changes made." ‘ setup
Set uiView = ws.CurrentView
Set view = uiView.View
Set coll = view.AllEntries ‘ get a list of all items
Set doc = coll.GetFirstEntry.Document
Forall item In coll.GetFirstEntry.Document.items
items = items & item.name & ","
End Forall ‘ tighten up the list
items = Split(items, ",")
items = Fulltrim(items)
items = Arrayunique(items) ‘ find out what action we are doing
If Msgbox("Click ‘No’ to replace values or to exit.", MB_YESNO, "Are you going to REMOVE a field?") = IDYES Then
action = kActionRemove
Elseif Msgbox("Click ‘No’ to exit.", MB_YESNO, "Then you must be REPLACING data in a field?") = IDYES Then
action = kActionReplace
Else
action = kActionNone
End If ‘ prompt for the item to change
If action <> kActionNone Then field = ws.Prompt(PROMPT_OKCANCELEDITCOMBO, "Please select the field you wish to " & action, "or enter a field manually.", "", items) Select Case action
Case kActionRemove
‘ verify the action
If Msgbox("Click ‘No’ to cancel.", MB_YESNO, "Are you sure you want to REMOVE " & field & " from all document in this view?") = IDYES Then
‘ loop through all docs in view and remove the item in question
Set entry = coll.GetFirstEntry
While Not entry Is Nothing
Set doc = entry.Document
‘ Call doc.RemoveItem(field)
‘ Call doc.Save(True,False)
Set entry = coll.GetNextEntry(entry)
Wend
msg = "Finished removing ‘" & field & "’ from all documents at " & Time()
Else
msg = kMsgNoActionDone
End If
Case kActionReplace
If Msgbox("This might take a few minutes as each document will be examined.", MB_YESNO, "Do you want see all the current values or type one in manually?") = IDYES Then
‘ grab all current entries
items = ""
Set entry = coll.GetFirstEntry
While Not entry Is Nothing
Set doc = entry.Document
items = items & doc.GetItemValue(field)(0) & ","
Set entry = coll.GetNextEntry(entry)
Wend ‘ tighten up the list
items = Split(items, ",")
items = Fulltrim(items)
items = Arrayunique(items) ‘ prompt for a new value
newValue = ws.Prompt(PROMPT_OKCANCELEDITCOMBO, "Please select the value you want to use", "or enter a value manually.", "", items)
Else
‘ prompt for a new value
newValue = Inputbox("Please enter the new value for ‘" & field & "")
End If ‘ verify the action
If Msgbox("Currently setting ‘" & field & "’ = ‘" & newValue &"’.", MB_YESNO, "Are you sure you want to set " & field & " = " & newValue & " for all documents in this view?") = IDYES Then
‘ Call coll.StampAll(field, newValue)
msg = "Finished stamping all documents with " & field & " = " & newValue & " at " & Time()
Else
msg = kMsgNoActionDone
End If
Case kActionNone
msg = kMsgNoActionDone
End Select ‘ fall through to print a message
ErrorHandler: If msg = "" Then msg = "Your action did not complete successfully. Please investigate. (" & Now() & ")" Msgbox msg
Exit Sub ‘ gets around "No Resume" error
End Sub

Original source : http://www.openntf.org/projects/codebin/codebin.ns…

Написано lotusnotes

Ноябрь 15, 2008 в 8:02

Опубликовано в Lotus Notes

Get Your Enterprise NAB from the current database ( shorten your code )

без комментариев

Function GetEnterpriseNAB( default As String ) As NotesDatabase
‘ returns the NAB from the server the current Db is on
‘ posted to http://www.openntf.org/projects/codebin/codebin.nsf/CodeBySubCategory/808CDC4680D8BF37862574EF006EDD01
‘ written by Mike Mortin
Dim s As New NotesSession
Dim db As NotesDatabase
Dim server As String
Dim nname As NotesName ‘ set the default
If default = "" Then default = "Admin01/Operations/CA" ‘ get our parent server to get the NAB
Set db = s.CurrentDatabase
Set nname = New NotesName(db.Server)
server = nname.Common ‘ now, use default server if we are local
If server = "" Then server = default ‘ finally, grab names.nsf from that server
Set GetEnterpriseNAB = New NotesDatabase(server, "names.nsf")
End Function

Original source : http://www.openntf.org/projects/codebin/codebin.ns…

Написано lotusnotes

Ноябрь 15, 2008 в 8:02

Опубликовано в Lotus Notes