| Person Update Agent to change Domain and Set Owner and Local Administrators Fields |
Tripp W Black on 11/13/2002 at 01:24 PM |
Category: Notes Developer Tips
Agents
|
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
|