Please help on this. I am trying to update active directory one field mail using .setifo.
I am able to get connection to LDAP using administartor id and password but looks like setinfo is not working .
I am not getting any errors also so unable to predict exact reason.
I am running the agent manually as of now using my LNID but in the agent user id and password is used to get connected to LDAP and that is AD admin id and password.
Is it like even after providing AD admin id and password it is taking my windows id and password due to which its not updating /setting as I have manager access to domino but not to AD (in AD my id has only read access).
Am I missing on something.
Do I need to save in AD after setting with setinfo or only Setinfo does both setting and saving.
I have not worked on LDAP much any guidance will be appreciated.
Thanks .
Code********************************
Sub Initialize
'On Error Goto errHandler
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim view As NotesView
Dim Vec As notesViewEntryCollection
Dim EM As String
Dim ShortName As String
Dim objConnection As Variant
Dim objCommand As Variant
Dim objRecordSet As Variant
Const ADS_SCOPE_SUBTREE = 2
'''''''''''''Profile setting On Domino''''''''''''''''''''''''''''''''''''''''''''''''
Set db = s.CurrentDatabase
Set view = db.GetView ("ADRJ")
Set vec = view.AllEntries
Set entry = vec.GetFirstEntry()
Set doc = entry.Document
count=vec.Count
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
objConnection.Properties("User ID") = "xx"
objConnection.Properties("Password") = "ewe"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
counter=0
While Not (doc Is Nothing)
shortname = doc.ShortName(0) ' from address book
SMTPID=doc.InternetAddress(0)
Set entry = vec.GetNextEntry(entry)
counter=counter+1
If doc.InternetAddress(0) <> "" Then
objCommand.CommandText = "SELECT * FROM 'LDAP://in.xx.ad.ss.com' WHERE sAMAccountName='"+shortname+"' "
Set objRecordSet = objCommand.Execute
ADcount=objRecordSet.RecordCount
If ( objRecordSet.RecordCount <> 0 ) Then
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
AnyChange = False
Set objUser = GetObject(objRecordSet.Fields("ADsPath").Value)
EM=objUser.mail
ADSHORTNAME=objUser.sAMAccountName 'just to check on shortname can be removed later
If EM <> SMTPID Then
AnyChange = True
objUser.put "mail", SMTPID
End If
If AnyChange =True Then
objUser.SetInfo
End If
objRecordSet.MoveNext
Loop
objRecordSet.close
End If
End If
Set doc = entry.Document
If counter=count Then
Exit Sub
End If
Wend
Exit Sub
'errHandler:
’ Msgbox "Error is : " & Error$ & " at line number : " & Cstr(Erl) & " in SearchLDAP() " & " while processing user : " & userName
Subject: Updating mail field from Domino to AD not working
From what I read you should be fine. I take it you stepped thru the code and got to the setinfo line without any issues? did you check in debugger that what you thought you set was actually set?
Subject: RE: Updating mail field from Domino to AD not working
Thanks Berry. I checked on the debugger and observation today were :Actually what is happening is id and password provided by me is AD administartors id and password and script is able to connect to AD , fetch the user but on .setinfo it is giving access denied error now , when I enabled error handler today.
Secondly , I tried checking by putting incorrect password as well just to check if it is taking id and password in this way or not while connection but yes it was accepting as I got error for unknown username/password on execute (Set objRecordSet = objCommand.Execute).
So if access is accepted for this id and password why .setinfo is not setting value in that AD field inspite of passing admin id n password , unable to predict the reason now.
Subject: RE: Updating mail field from Domino to AD not working
If you are getting an access denied error then it is clearly a permission issue with the account you are using to update ad. Speak to your windows admin.
Subject: RE: Updating mail field from Domino to AD not working
Is there a possibility that even after providing admins id and password somehow script is taking my windows id and password credentials and not allowing updating the field in AD.
Subject: RE: Updating mail field from Domino to AD not working
Final code:Now this is working with some changes done while passing id and password.
Sub Initialize
On Error Goto errHandler
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc,LogDoc As NotesDocument
Dim view As NotesView
Dim Vec As NotesViewEntryCollection
Dim entry As NotesViewEntry
Dim count,counter As Integer
Dim SMTPID As String
Dim EM As String
Dim ShortName As String
Dim objConnection As Variant
Dim objCommand As Variant
Dim objRecordSet As Variant
Const ADS_SCOPE_SUBTREE = 2
'''''''''''''Profile setting On Domino''''''''''''''''''''''''''''''''''''''''''''''''
Set db = s.CurrentDatabase
Set view = db.GetView ("ADRJ")
Set vec = view.AllEntries
Set entry = vec.GetFirstEntry()
Set doc = entry.Document
count=vec.Count
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
counter=0
While Not (doc Is Nothing)
shortname = doc.ShortName(0) ' from address book
SMTPID=doc.InternetAddress(0) ' from address book
Set entry = vec.GetNextEntry(entry)
counter=counter+1
If doc.InternetAddress(0) <> "" Then 'Restricting passing of blank smtpid from Address book
objCommand.CommandText = "SELECT * FROM 'LDAP://in.nam.ad.xyz.com' WHERE sAMAccountName='"+shortname+"' "
'Set objRecordSet = objCommand.Execute
Set objRecordSet =CreateObject("ADODB.recordset")
'objRecordSet.Open objCommand,,,3
objRecordSet.Open objCommand
ADcount=objRecordSet.RecordCount
If ( objRecordSet.RecordCount <> 0 ) Then
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
AnyChange = False
Set ou = GetObject("LDAP:")
Set objUser=ou.OpenDSObject(objRecordSet.Fields("ADsPath").Value,"IN\userid","password" ,1) 'Passing userid and password
EM=objUser.mail 'storing smtpid from AD
ADSHORTNAME=objUser.sAMAccountName 'shortname from AD
If EM <> SMTPID Then 'if AD smtpid is not equal to domino smtpid then value will be put to AD from Domino
AnyChange = True
objUser.put "mail", CStr(SMTPID)
End If
If AnyChange =True Then
objUser.SetInfo 'explicitly setting the value to AD
updatedlog= updatedlog & Chr(10)& "Record updated for - " & ADSHORTNAME & " earlier id was '" & EM & "' new id updated as '"& objUser.mail &"'"
End If
objRecordSet.MoveNext
Loop
objRecordSet.close
End If
End If
Set doc = entry.Document
If counter=count Then
' update log can be saved or sent on memo Exit Sub
End If
Wend
Exit Sub
errHandler:
msgbox "Error is : " & Error$ & " at line number : " & Cstr(Erl) & " in SearchLDAP() " & " while processing user : " & shortname