Finding a User's E-mail Address in the User Directory

See Also

The following example uses the modFindUserEmailInUserList function to locate a user's e-mail address based on the user's SAMAccountName.

For example, you can add the modFindUserEmailInUserList function to an action to identify a user's e-mail address when an issue is opened or closed. Then, you can use the modSendMail function to send the e-mail to the address located using modFindUserEmailInUserList.

To use this example, add the function call to the script procedure on the Shared Script tab in the Workflow Process pane. Then, add the following example code to the beginning or end of the text in the Shared Script tab.

Calling the Function

'// modFindUserEmailInUserList
'//
'// -----------------------------------------------------------------------------------
    ret = modFindUserEmailInUserList("owner")
    call logger.printstring("user email from owner: " & ret & chr(13) & chr(10))
'// -----------------------------------------------------------------------------------

Example Script

'// ------------------------------------------------------------------------------------
'// Name      : modFindUserEmailInUserList
'// Purpose   : finds an e-mail address for the user from modUserList based 
'	           on Session.Item() data
'//
'// Prereq    : none
'//           :
'// Inputs    : strItem - name of Session.Item() value that equates to a SAMAccountName
'//
'// Return    : User e-mail name if function succeeds, otherwise zero length string ""
'// ------------------------------------------------------------------------------------
Function modFindUserEmailInUserList(strItem)

    '// declarations
    Dim strUL_SAM
    Dim strUL_MAIL
  
    '// init UL vars
    strUL_SAM = "SAMAccountName"
    strUL_MAIL = "mail"

    '// assume failure
    modFindUserEmailInUserList = ""

    Set ulist = Session.userlist
    
    On Error Resume Next
    '// find user in userlist
    ulist.MoveFirst
    ulist.Find strUL_SAM & "='" & Session.Item(strItem) & "'"
    
    '// check for fail
    If Err Or ulist.EOF Or ulist.BOF Then
        Exit Function
    Else
        On Error GoTo 0
        modFindUserEmailInUserList = ulist(strUL_MAIL)
    End If
   
End Function