Share via


Finding a Manager in the User Directory

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The following example uses the modFindMgrEmailInUserList function to locate the current user's manager in the modUserList table. This example can be used in conjunction with other examples. For example, use the modSendMailToMgr function to send e-mail to a manager after the modFindMgrEmailInUserList function locates the manager information.

You can add the modFindMgrEmailInUserList function to an event to assign an issue to a manager for review or closure when the user chooses to resolve the issue.

To use this example, add the "Calling the Function" code to the appropriate script procedure, and add the "Example Script" code wherever you usually store functions.

Calling the Function

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

Example Script

'// ----------------------------------------------------------------
'// Name      : modFindMgrInUserList
'// Purpose   : Finds a manager from modUserList table info based on SAMAccountInfo
'//
'// Prereq    : none
'// Inputs    : strItem - name of Session.Item() value that equates to a SAMAccountName
'//           : strDefault - where to send e-mail if unable to find user or manager
'//           : strFrom - name to use for sending e-mail
'//           : strSubject - subject of e-mail
'//           : strBody - body of e-mail
'//
'// Return    : managerEmailName if succeeds, otherwise zero length string ""
'// -----------------------------------------------------------------
Function modFindMgrEmailInUserList(strItem)

    '// declarations
    Dim strManagerSID
    Dim strManagerSAM
    Dim strUserSAM
    Dim strUL_SAM
    Dim strUL_OBJSID
    Dim strUL_MGR
  
    '// initialize user directory variables
    strUL_SAM = "SAMAccountName"
    strUL_OBJSID = "objectsid"
    strUL_MGR = "manager"
    strUL_MAIL = "mail"

    '// assume failure
    modFindMgrEmailInUserList = ""

    '// in case unable to find a manager in the modUserList
    '// where you want to send e-mail

    Set ulist = Session.userlist
    On Error Resume Next
    '// find user in modUserList
    ulist.MoveFirst
    ulist.Find strUL_SAM & "='" & Session.Item(strItem) & "'"
    
    '// check for failure
    If Err Or ulist.EOF Or ulist.BOF Then
        Exit Function
    Else
        On Error GoTo 0
        '// get the manager sid
        strManagerSID = ulist(strUL_MGR)

        '// go back to the top of the modUserList and find the manager
        ulist.MoveFirst
        On Error Resume Next
        ulist.Find strUL_OBJSID & "='" & strManagerSID & "'"
        '// check for failure
        If Err Or ulist.EOF Or ulist.BOF Then
            Exit Function
        Else
            modFindMgrEmailInUserList = ulist(strUL_MAIL)
        End If
    End If
   
End Function

See Also

Script Examples for SQL Server | Finding a User's E-Mail Address in the User Directory | Sending Mail Using SMTP | Sending Mail to a Manager | Calling a Stored Procedure