Check Duplicate EmployeeID field

Author Message
gilvicente.araujo

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 1/31/2012
  • Status: offline
Check Duplicate EmployeeID field Tuesday, January 31, 2012 6:48 AM (permalink)
0

Check Duplicate EmployeeID field

 
I'm looking for a vbscript that checks if the value that will gonna be signed to an employeeID field already exists in the other users accounts.  
I starting using this generic code for employeeID insertion:  
dim oVar, oUsr, tmp, title, text1 
set oVar = wscript.arguments 
set oUsr = getobject(oVar(0)) 
title = "EmployeeID Insertion" 
text1 = "Actual EmployeeID: " & oUsr.employeeID & vbcrlf & vbcrlf & "Insert or Update the EmployeeID:" & vbcrlf & vbcrlf & "(Ex: 75309889078)" 
tmp = inputbox(text1,title) 
if tmp <> "" then oUsr.put "employeeID",tmp 
oUsr.setinfo 
set oUsr = Nothing 
wscript.quit  
But now I have to tune the code with this condition: Don't exists two OR MORE users accounts with the same employeeID, and this field have to be 11 numeric characters.


<message edited by gilvicente.araujo on Tuesday, January 31, 2012 6:52 AM>
 
#1
    59cobalt

    • Total Posts : 969
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:Check Duplicate EmployeeID field Tuesday, January 31, 2012 10:23 AM (permalink)
    0
    Any particular reason to not use the GUID that is assigned to the account anyway?
     
    #2
      gilvicente.araujo

      • Total Posts : 2
      • Scores: 0
      • Reward points : 0
      • Joined: 1/31/2012
      • Status: offline
      Re:Check Duplicate EmployeeID field Tuesday, January 31, 2012 11:26 PM (permalink)
      0
      Thanks for reply,
      But it's just a core business need.
      The application will use the EmployeeID to make references in our ERP.
      In order to make a clean job I just wanna enforce uniqueness in this field.
      Any code behind the hood?
       
      #3
        59cobalt

        • Total Posts : 969
        • Scores: 91
        • Reward points : 0
        • Joined: 7/17/2011
        • Status: offline
        Re:Check Duplicate EmployeeID field Wednesday, February 01, 2012 7:59 AM (permalink)
        0
        You'd need to change the schema to really enforce uniqueness (assuming that's possible at all, not sure about it). And even if it's possible, changes to standard attributes in the schema are strongly discouraged.

        If this is a business requirement, as you say: don't you have an HR system in place that already gives you unique employee IDs? Then you'd simply need to write that ID to the employeeID attribute of the respective user.

        I doubt that it's possible to do what you want with VBScript, because you'd need a write-lock on the entire AD during the check/update process to avoid race conditions.

        Of course, if you don't care about race conditions, you could always use an LDAP filter to enumerate (only) users with a matching employeeID field from AD:
        Set objRootDSE = GetObject("LDAP://RootDSE")
        base       = "<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">"
        filter     = "(&(objectCategory=person)(objectClass=user)(employeeID=" & tmp & "))"
        attributes = "sAMAccountName"
        scope      = "subtree"
        
        Set adoConn = CreateObject("ADODB.Connection")
        adoConn.Provider = "ADsDSOObject"
        adoConn.Open "Active Directory Provider"
        
        Set adoCmd = CreateObject("ADODB.Command")
        adoCmd.ActiveConnection = adoConn
        adoCmd.Properties("Page Size") = 100
        adoCmd.Properties("Timeout") = 30
        adoCmd.Properties("Cache Results") = False
        adoCmd.CommandText = base & ";" & filter & ";" & attributes & ";" & scope
        
        Set rs = adoCmd.Execute
        
        If rs.RecordCount > 1 Then WScript.Echo "Duplicate employeeID found."
        
        rs.Close
        adoConn.Close

         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9