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

Parents
  • A few suggestions. 

    1. Use the "Test script" feature in the Designer to test your code.

    2. Read the SDKs.  If you have the ISO, it's location here:  Modules\QBM\dvd\AddOn\SDK\ScriptSamples\03 Using database objects

    3. Study the code.  This specific code will search the DB to create a dictionary so that the when you create a new email, there's no duplicate.  If there is, then the code would have added an incremental number to it.  It appears like you removed that condition.

    So what do you need to do?

    1. Get the Person object because there's no reference to get the FirstName/LastName.

    Dim myPerson As ISingleDbObject
    'load Person
    myPerson = Connection.CreateSingle("Person", uidperson)

    2. Create the new email address

    Dim newDefaultEmailAddress As String = myPerson.GetValue("FirstName").ToString().Substring(0,1) &  myPerson.GetValue("LastName").ToString().Substring(0,1) & maildom

    3. Make sure that the new email address does not exist

    4. Set the new email address

    You can use my examples and plug into your code to make it work. 

    Good luck!

  • Thank you so much for this detailed reply. I really appreciate it.

    I also wasn't aware there was test script feature and SDKs on the ISO.

Reply Children
No Data