Sorry, never mind, figured it out.

Where pHL7 is the EnsLib.HL7.Message, execute:

do pHL7.BuildMap(0)

After that, reference pHL7.GetSegmentPath(*) to get the schema path (replacing * with the segment number, e.g. in the screenshot in my original post, PV1 was row 5, so pHL7.GetSegmentPath(5) = "PIDgrp(1).PV1").

For my loop I'm referencing pHL7.SegCount, e.g:

i=1:1:pHL7.SegCount pHL7.GetSegmentPath(i),! }

Thanks Marcel, that's a good idea. That'd work well I think if we needed to store credentials for many different domains. However we only have one domain in our organisation - my concern was around declaring/storing the username and password in plain text in the code, whereas I wouldn't mind doing that for the domain.

However, that said, I wasn't aware until now that the credentials stored in Ensemble could be pulled back in plain text using that code. I assumed as they're obfuscated in the front end that they'd be encrypted in some fashion, but the code Michael provided can be used to trace them out in plain text (or write them out in Terminal). Not as secure as I'd imagined, but still somewhat of a step up from writing them in the method's code.

Thanks for letting me know Katherine, I guess I've just written a method which isn't actually using the adapter at all. I'll check out the %Net.LDAP.Client documentation and see if I can rework it.

Thanks Michael, that's a handy bit of code, worked great :)