Link to home
Start Free TrialLog in
Avatar of alvshill24
alvshill24

asked on

Connecting to a Directory Service via LDAP using Lotus Script

I'm having real difficult getting a piece of code in VBScript to work properly in Lotus Notes via Lotus Script.  When I do the debug, all is fine until a line which uses GetObject, after which it gives a type mismatch error.  I've since found out that two parameters are required for GetObject in Lotus Script GetObject(Path, Class) whereas the script works perfectly well in VB Script.

Please can somebody let me know which modifications I need to make to get this code working in Lotus Notes
Set ADOConn = CreateObject("ADODB.Connection")
ADOConn.Provider = "ADsDSOObject"
ADOConn.Open "ADs Provider"
		
Set ADOCommand = CreateObject("ADODB.Command")
		
Set ADOCommand.ActiveConnection = ADOConn
		
ADOCommand.CommandText = "<LDAP://uk-bre-cts-vsed-read1.acme.com/dc=acme,dc=com>;(&(objectclass=acmeperson)(uid=bloggs01));adspath;Subtree"
		
Set RS = ADOCommand.Execute
		
If Not rs.eof Then
		
  While Not RS.EOF
		
    Set objUser = GetObject("", RS.Fields("adspath"))
		
    wscript.echo "BU_Cat,"& objuser.get("businesscategory")
    wscript.echo "Country short,"& objuser.get("c")
    wscript.echo "Surname, Forename,"& objuser.get("cn")
    wscript.echo "Country full,"& objuser.get("co")
		
    RS.MoveNext
  Wend
		
End If
		
RS.Close
Set ADOConn = Nothing
Set ADOCommand = Nothing
Set RS = Nothing

Open in new window

Avatar of olaraak
olaraak
Flag of Estonia image

Sorry about misunderstanding, but where and how you run this script?

If you try to run it as LotusScript, there are differences indeed.

For example, LotusScript does not support identifying arguments for OLE methods or properties by name rather than by the order in which they appear. So, maybe you need to reference GetObject("", RS.Fields("adspath")) by index instead of name.

To clarify what's causing the error, include error trapping:
on error goto errorhandler before other code,
Print  Str(Err) & " " & Error$ & " on row " & Cstr(Erl) in errorhandler:
Avatar of alvshill24
alvshill24

ASKER

Hi olaraak

The script is run in the PostOpen event of a form.  I identified the issue by turning on LotusScript debugging and stepping through the script using 'Step Into'.  I'll put the error handler in though and feed back it's results.

By the way, the set objuser line (from  the VB Script I adapted the LotusScript code from) was originally: -

Set objUser = GetObject(RS.Fields("adspath"))

In the code I post on this forum, I realised that I'd left in the version that I experimented with, where I used a blank parameter in the hope that is would give Notes what it needed.
Ok I get

"Error 13 Type mismatch" corresponding to this line: -
Set objUser = GetObject(RS.Fields("adspath"))

and then

"Error 213 ADODB.Recordset: Item cannot be found in the collection corresponding to the requested name or ordinal." corresponding to this line: -

wscript.echo "BU_Cat,"& objuser.get("businesscategory")

I must apologise as in the Lotus Script i'm actually using the Msgbox command like below.  I had the wscript.echo command lines commented out (as they were directly from the VBScript code).  I was going to convert them for use once I'd managed to successfully retrieve a single value.  Please ignore the wscript lines and regard the line below as I post I'd posted in the code.

Msgbox "NotesDn,"& rs.fields("gsknotesdn").Value
Try to reference parameters by index instead of parameter name.
I have no idea what the index name should be, or how this particular command (GetObject) should be formatted to work properly in Lotusscript hence my problem.  Any idea as to how I could find out?

Fyi: I first learned of the differences between Lotusscript and VBScript regard GetObject here: -
http://notes.utk.edu/help/help6_designer.nsf/b3266a3c17f9bb7085256b870069c0a9/17b6311e203650bf85256c1c003fbb5a?OpenDocument
You should somehow get the sequence numbers of parameters.
Maybe in Visual Basic, loop through parameters and get their names together with index number 0...N

Set objUser = GetObject("", RS.Fields(0)) ' Replace 0 with actual number of parameter "adspath"

At first you just try with index number 0 to see if the error goes away.
Thanks for your help.  I don't think this can be done via LotusScript.  I've since found out about some Java agents that are are being successfully used in my company and will use these instead.
ASKER CERTIFIED SOLUTION
Avatar of ee_auto
ee_auto

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial