The Person Creation Sample Agent:
Used to loop through and create a range of users based on locations. It does NOT create a mail file. That would need to be added.
(You can also use a spreadsheet CSV file for importation when you want mail.)
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase ' current db
Dim pV As NotesView ' $VIMPeople view of users
Dim pDoc As NotesDocument ' person document
Dim pclienttype As String ' type of person doc (mail or not)
Dim pmailsystem As String ' type of mail server - constant
Dim pmaildomain As String ' mail domain - constant
Dim pmailaddress As String ' forwarding mail address field
Dim pinternetaddress As String ' internet address/e-mail address field
Dim pshortname As String ' ShortName field (prefix + counter value + suffix)
Dim plastname As String ' LastName field (prefix + counter value + suffix)
Dim fnm() As String ' FullName field array
Dim fpaddnum As Integer ' number of digits to pad location string/number
Dim fnmprefix As String ' name prefix
Dim fnmsuffix As String ' ou suffix
Dim fnmorghier As String ' org ending for full name
Dim femailsuffix As String ' e-mail suffix of this system
Dim forwardemailsuffix As String ' forwarding e-mail address
Dim numstart As Integer ' starting loc number
Dim numend As Integer ' ending loc number
Dim counter As Integer ' counter for looping numstart to numend
Dim padstr As String ' location number padded
On Error Goto SErrorHandler
' ***************** customize below ****************
Redim fnm(3) ' update for extra full name values, then update the values within the loop
pclienttype = "0"
pmailsystem = "5" ' Notes -1, Other Internet Mail-5, None-100
pmaildomain = ""
fnmprefix = "DC"
fnmsuffix = "Distribtuion"
fnmorghier = "/OU=Department/O=Organization"
femailsuffix = "@mycompanydomain.com"
forwardemailsuffix = "@myothercompanyname.org" ' leave blank for no forward e-mail
numstart = 123
numend = 233
fpaddnum = 4
' **************************************************
' setup
Set db = s.CurrentDatabase
Set pV = db.GetView("($VIMPeople)")
' test mail system for null
If (pmailsystem = "") Then
pmailsystem = "100"
End If
' loop and process
For counter = numstart To numend
' build last name
plastname = fnmprefix & PadString(Cstr(counter), fpaddnum) & fnmsuffix
' build shortname
pshortname = Fulltrim(fnmprefix & PadString(Cstr(counter), fpaddnum) & fnmsuffix)
' update FullName array below to padding and lines needed for client
fnm(0) = fnmprefix & PadString(Cstr(counter), fpaddnum) & fnmsuffix & fnmorghier
fnm(1) = fnmprefix & PadString(Cstr(counter), fpaddnum) & fnmsuffix
fnm(2) = fnmprefix & PadString(Cstr(counter), fpaddnum) & fnmsuffix & femailsuffix
fnm(3) = fnmprefix & PadString(Cstr(counter), 5) & fnmsuffix & fnmorghier
' build e-mail address and forward e-mail address
If (femailsuffix = "") Then
' no e-mail (hopefully mailsystem is 100)
pinternetaddress = ""
Else
' has e-mail address
pinternetaddress = fnmprefix & PadString(Cstr(counter), 4) & fnmsuffix & femailsuffix
End If
If (forwardemailsuffix = "") Then
' no forwarding address
pmailaddress = ""
Else
' has forward address
pmailaddress = fnmprefix & PadString(Cstr(counter), 4) & fnmsuffix & forwardemailsuffix
End If
' check if name exists already
Set pDoc = pV.GetDocumentByKey(fnm(0), True)
If Not (pDoc Is Nothing) Then
' skip - person already exists
Else
' create the person record
Set pDoc = db.CreateDocument()
Call pDoc.ReplaceItemValue("Form", "Person")
Call pDoc.ReplaceItemValue("Type", "Person")
Call pDoc.ReplaceItemValue("ClientType", pclienttype)
Call pDoc.ReplaceItemValue("LastName", plastname)
Call pDoc.ReplaceItemValue("ShortName", pshortname)
Call pDoc.ReplaceItemValue("MailDomain", pmaildomain)
Select Case pmailsystem
Case "1"
' notes
Call pDoc.ReplaceItemValue("MailSystem", pmailsystem)
' populate e-mail address
Call pDoc.ReplaceItemValue("InternetAddress", pinternetaddress)
Call pDoc.ReplaceItemValue("MailAddress", pmailaddress)
Case "5"
' other internet mail
Call pDoc.ReplaceItemValue("MailSystem", pmailsystem)
Call pDoc.ReplaceItemValue("InternetAddress", pinternetaddress)
Call pDoc.ReplaceItemValue("MailAddress", pmailaddress)
Case Else
' none (100 or "")
Call pDoc.ReplaceItemValue("MailSystem", "100")
Call pDoc.ReplaceItemValue("InternetAddress", "")
Call pDoc.ReplaceItemValue("MailAddress", "")
End Select
' save the complete person doc
Call pDoc.ComputeWithForm(False, False)
Call pDoc.Save(True, False)
End If
' loop to next location
Next counter
SExit:
Exit Sub
SErrorHandler:
Print "Error: " & Cstr(Err) & " " & Error$ & ", line: " & Cstr(Erl) & "."
Resume SExit
End Sub
Function PadString(origstring As String, pads As Integer)
' this function pads/adds leading 0s to a number string
Dim padding As String ' string of zeros used for padding
padding = "00000000000000000000000000000000000000000"
If Len(pads) = 0 Then
' return original string as error
PadString = origstring
End If
PadString = Right(padding & origstring, pads)
End Function
The Person Creation Sample Agent:
Used to loop through update the FullName field when business Organizational changes require that all person docs be factored.
Use the following code to update selected person documents. Updates are:
- Domain name changed by resetting the person document's user name field (FullName field)
- Owner field has added the fullname of person
- Local Admin field has added LocalDomainAdmins group and a user selected admin group.
Code below should be placed in an agent that is run on selected documents.
Sub Initialize
' agents updates selected person records and replaces domain with new domain
' how - uses full name and replaces user name
Dim s As New NotesSession
Dim w As New NotesUIWorkspace
Dim db As NotesDatabase ' this database
Dim dc As NotesDocumentCollection ' unprocessed documents - the documents user selected
Dim doc As NotesDocument ' current document being processed
Dim ndoc As NotesDocument ' next document after current document
Dim question As Variant ' new domain entered by user
Dim firstname As String ' firstname field from doc
Dim mi As String ' middleinitial field from doc
Dim lastname As String ' lastname field from doc
Dim commonname As String ' fullname/cn of person - made from first, mi, and last name fields
Dim fullname(1) As String ' username with domain - replaces value of existing fullname field in doc (0-name w/domain, 1-cn name)
Dim domain As String ' domain name to be appended to fullname
Dim item As NotesItem ' fields to be updated
Dim question2 As Variant ' who is local administrator, added by user
Dim localadmin() As String ' local admins of person doc - is question2 answer plus LocalDomainAdmins group
' get collection so we know there is at least one document selected...
Set db = s.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument()
If (doc Is Nothing) Then
' prompt user that no documents were selected and exit
Messagebox "Sorry. No documents seem to have been selected. Please select some documents before running this code."
Exit Sub
End If
' set domain to sample for user
domain="Acme" ' example prompt
' ask user for new domain
question = w.Prompt (PROMPT_OKCANCELEDIT, "New Domain", _
"Enter the new domain to replace the domain for the selected users.", _
domain)
If Isempty (question) Then
Messagebox "Domain rename cancelled."
Exit Sub
Else
domain = question
Messagebox "Thank you. Ready to begin domain replacement."
End If
' ask user for local administrator group
question2 = w.Prompt (PROMPT_OKCANCELEDIT, "Local Administrator Group", _
"Enter the local administrative group for the selected users.", _
"")
If Isempty (question2) Then
Messagebox "Only LocalDomainAdmin group will be added."
Redim Preserve localadmin(0)
localadmin(0) = "LocalDominAdmins"
Else
Messagebox "Thank you. I will add " & question2 & " and the LocalDomainAdmins group as local administrators."
Redim Preserve localadmin(1)
localadmin(0) = question2
localadmin(1) = "LocalDominAdmins"
End If
' loop through and begin replacement
While Not(doc Is Nothing)
' build a new name using firstname, middleinitial, and lastname
firstname = doc.FirstName(0)
mi = doc.MiddleInitial(0)
lastname = doc.LastName(0)
' combine name components
If firstname<>"" And mi<>"" Then
commonname = firstname & " " & mi & " " & lastname
Else
If firstname<>"" And mi="" Then
commonname = firstname & " " & lastname
Else
commonname = lastname
End If
End If
' setup fullname replacement values
fullname(0) = commonname & "/" & domain
fullname(1) = commonname
' replace current username values
Set item = doc.ReplaceItemValue( "Fullname", fullname)
' replace owner field
Set item = doc.ReplaceItemValue ("Owner", fullname(0))
' set administrators field
Set item = doc.ReplaceItemValue("LocalAdmin", localadmin)
' save doc
Call doc.Save(True,False)
' cycle to next doc
Set doc = dc.GetNextDocument(doc)
Wend
End Sub
previous page
|