Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with AD query, empty values and form field population

Status
Not open for further replies.

GessWurker1

Technical User
Aug 17, 2019
5
US
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,physicaldeliveryofficename,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

Else
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?

Thanks,

--Timothy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top