I have the following script to create the central user account= First Initial and lastName.If the same first name and last name exist add numerical valvue to the UserID created. But my script is creating only LastName as Central User Account. Please help?
Here is my script:
#If Not SCRIPTDEBUGGER Then
Imports System.Collections.Generic
Imports System.Data
#End If
Public Function AFO_BuildCentralAccountGlobalUnique(ByVal uid_person As String, ByVal Lastname As String, ByVal Firstname As String, ByVal FirstInitial As String) As String
Dim i As Int32
Dim account As String
Dim accountPrefix As String
Dim f As ISqlFormatter = Connection.SqlFormatter
AFO_BuildCentralAccountGlobalUnique = String.Empty
Firstname = VI_AE_FormatConvertUmlaut_Sonderzeichen(Firstname)
Lastname = VI_AE_FormatConvertUmlaut_Sonderzeichen(Lastname)
If Firstname.Length > 0 And Lastname.Length > 0 Then
If FirstInitial.Length + Lastname.Length <= 19 Then
account = FirstInitial & Lastname
Else
account = FirstInitial & Lastname.Substring(0, 1)
End If
ElseIf Firstname.Length > 0 Then
account = FirstInitial & Lastname
Else
account = FirstInitial & Lastname.Substring(0, 1)
End If
'account = VI_AE_FormatConvertUmlaut_Sonderzeichen(account)
accountPrefix = account
'fill existing addresses in a dictionary
Dim existing As New Dictionary(Of String, Object)(StringComparer.OrdinalIgnoreCase)
Dim dummy As New Object()
Dim dummyPerson As ISingleDbObject
dummyPerson = Connection.CreateSingle("Person")
Dim pattern As String = accountPrefix & "%"
Dim myObjectKey As New DbObjectKey("Person", uid_person)
Using rd As IDataReader = CType(dummyPerson.Custom.CallMethod("SearchCentralAccount", pattern), IDataReader)
While rd.Read()
Dim accountName As String
Dim objectKeyString As String
Dim objectKey As DbObjectKey
accountName = rd.GetString(rd.GetOrdinal("AccountName"))
objectKeyString = rd.GetString(rd.GetOrdinal("ObjectKeyPerson"))
If Not String.IsNullOrEmpty(objectKeyString) Then
objectKey = New DbObjectKey(objectKeyString)
'only addresses which not belong to the actual employee will be considered
If myObjectKey.Equals(objectKey) Then
Continue While
End If
End If
existing(accountName) = dummy
End While
End Using
While True
Dim centralAccount As String = account
' Does not exists?
If Not existing.ContainsKey(centralAccount) Then
Return centralAccount.ToLowerInvariant()
End If
' next trial
i = i + 1
If i = 1 And account.Length <= 18 Then
account = accountPrefix & FirstInitial.Substring(0, 1) & Lastname
ElseIf account.Length <= 19 And i <= 9 Then
account = accountPrefix & CStr(i)
ElseIf i <= 9 Then
account = accountPrefix.Remove(accountPrefix.Length - 1, 1) & CStr(i)
Else
account = accountPrefix.Remove(accountPrefix.Length - 1, 2) & CStr(i)
End If
End While
End Function