This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Creating unique defaultMailAddress

Hello all, I was hoping someone could assist me with creating a defaultMailAddress that isn't linked to my central account. I have the logic I want to use but I cannot make much sense of the below script.

What I'm trying to do is defaultMailAddress = Firstname.Trim().Substring(0,1) & Lastname.Trim().Substring(0,1) then auto increment number. Any suggestions would be greatly appreciated. I spent two days and go no where, it's seemingly tied to the CentralAccount.

This is the template: 

#If EX2K Or NOTES Then
Dim defaultMailAddress As String
If Len($CentralAccount$) > 0 AndAlso Len ($UID_Person$) > 0 Then
defaultMailAddress = SCC_VI_AE_CreatedefaultMailAddress($centralaccount$,$uid_person$,$CustomProperty04$)
' check if mail address is valid
If VID_IsSMTPAddress(defaultMailAddress) Then
Value = defaultMailAddress
End If
End If
#End If

This is the Script: SCC_VI_AE_CreatedefaultMailAddress

#If Not SCRIPTDEBUGGER Then
Imports System.Collections.Generic
Imports System.Data
#End If

Public Function SCC_VI_AE_CreatedefaultMailAddress(ByVal centralaccount As String, ByVal uidperson As String,ByVal customProperty4 As String) As String
Dim i As Int32 = 0
Dim account As String = SCC_VI_AE_FormatConvertUmlaut_Sonderzeichen(centralaccount)
Dim prefix As String = account
Dim maildom As String = String.Empty
Dim f As ISqlFormatter = Connection.SqlFormatter

SCC_VI_AE_CreatedefaultMailAddress = String.Empty

If Connection.GetConfigParm("TargetSystem\Notes") = "1" Then
maildom = Connection.GetConfigParm("TargetSystem\Notes\DefaultMailDomain")
End If

If Connection.GetConfigParm("TargetSystem\ADS\Exchange2000") = "1" Then
maildom = Connection.GetConfigParm("TargetSystem\ADS\Exchange2000\DefaultMailDomain")
End If

If maildom = "" Then
Exit Function
Else
If Not maildom.StartsWith("@") Then
maildom = "@" & maildom
End If
End If

' 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 = prefix & "%" & maildom
Dim myObjectKey As New DbObjectKey("Person", uidperson)

Using rd As IDataReader = CType(dummyPerson.Custom.CallMethod("SearchMailAddresses", pattern), IDataReader)

While rd.Read()
Dim address As String
Dim objectKeyString As String
Dim objectKey As DbObjectKey

address = rd.GetString(rd.GetOrdinal("smtp"))
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(address) = dummy
End While
End Using

While True
Return account
End While
End Function