Results 1 to 2 of 2

Thread: ASP crash - AD query and problem with AD profiles missing "initials"

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2021

    ASP crash - AD query and problem with AD profiles missing "initials"

    Hi - I'm running into trouble with my AD query when an AD profile lacks a middle initial. Here's the vbscript snippet

    strRSUser = "SELECT displayname,givenName,initials,sn,employeeID,postalcode,memberOf,objectCategory,physicaldeliveryoffi cename,mail,manager FROM 'LDAP://" & strDomain &"' WHERE samaccountname = '"& varUser &"' ORDER by name "
    rsUser.Open strRSUser, connAD,1,1

    ' Make sure recordset is not empty (i.e. this is a valid user) and then set the session variables
    If NOT (rsUser.BOF AND rsUser.EOF) Then
    Dim varInitials
    Session("userAccess") = 1
    varEmail = rsUser.Fields.Item("mail").Value
    varEmployeeID = rsUser.Fields.Item("employeeID").Value
    varFirstName = rsUser.Fields.Item("givenName").Value
    varInitials = rsUser.Fields.Item("initials").Value
    varLastName = rsUser.Fields.Item("sn").Value
    varOffice = rsUser.Fields.Item("physicaldeliveryofficename").Value
    varInitialsChk = IsEmpty(varInitials)
    Session.Timeout = 60

    Session("userAccess") = 0

    ' End valid user check
    End If

    My problem:

    I need to account for the possibility that varInitials may be nonexistent. Haven't found a way to do it. Consequently, the javascript line below breaks for users without a middle initial in AD. So far, my only solution is to leave out varInitials entirely, but that's not ideal. When varInitials are present, I want to populate the from field with them:

    "if(emptyString.test(theForm.ctl00$ctl00$mpcSingleContent$cntrlID_23172.value)) {" & vbCrLf & _
    " theForm.ctl00$ctl00$mpcSingleContent$cntrlID_23172.value = """ + varLastName + ", " + varFirstName + " " + varInitials + """" & vbCrLf & _
    "}" & vbCrLf & _

    Who can help?



  2. #2
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Idaho Falls, Idaho USA

    Re: ASP crash - AD query and problem with AD profiles missing "initials"

    Change your JavaScript code to check to see if varInitials contains any data, If yes, use your existing code, otherwise, use a modified version that leaves out the initials.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width