In addition, here is a sample for updating an attribute in LDAP - First you need to search for the correct entry in LDAP so you would be update it.

Method UpdateSingleValue(pRequest As LDAP.REQ.SetSingleValueAttributes, Output pResponse As LDAP.RES.SetSingleValueAttributes) As %Status
{
    #dim tEntries as %Net.LDAP.Client.Entries
    #dim ent as %Net.LDAP.Client.Entry
    Set pResponse=##class(LDAP.RES.SetSingleValueAttributes).%New()
    try {

     // sample input data

        //set pRequest.UserName="kerensk"
        //set x=##class(LDAP.REQ.AttributeInfo).%New()
        //set x.AttributeName="employeeID"
        //set x.AttributeValue="12345"
        //set y=##class(LDAP.REQ.AttributeInfo).%New()
        //set y.AttributeName="countryCode"
        //set y.AttributeValue="33"
        //do pRequest.AttributeNames.Insert(x)
        //do pRequest.AttributeNames.Insert(y)
        
        
        // prepare search parameters
        set Filter="SAMAccountName="_pRequest.UserName
        if pRequest.AttributeNames.Count()=0 {
            set pResponse.Success=0
            set pResponse.ErrorMessage="Empty attributes list"
            quit
        }
        if pRequest.UserName="" {
            set pResponse.Success=0
            set pResponse.ErrorMessage="Empty username parameter"
            quit
        }
        
        // search
        Set tSC=..Adapter.Search(.tEntries,2,Filter,"")
        if $$$ISERR(tSC) {
            set pResponse.Success=0
            set pResponse.ErrorMessage=$system.Status.GetErrorText(tSC)
            quit
        }
        if '$IsObject(tEntries) {
            set pResponse.Success=0
            set pResponse.ErrorMessage="User does not exist"
            quit
        }
        set ent=tEntries.GetNext("")
        
        if ($IsObject(ent)) {
               Set editParam = ##class(%Net.LDAP.Client.EditEntry).%New()
               Set editParam = tEntries.EditCurEntry()
            for i=1:1:pRequest.AttributeNames.Count() {
                   do editParam.Replace(pRequest.AttributeNames.GetAt(i).AttributeName,pRequest.AttributeNames.GetAt(i).AttributeValue,0)
            }
               set tSC = editParam.Commit()
            $$$TRACE("Commit="_$system.Status.GetErrorText(tSC))
            if $$$ISERR(tSC) {
                set pResponse.Success=0
                set pResponse.ErrorMessage=$system.Status.GetErrorText(tSC)
                quit
            }
         }
    }
    catch Err {
        set tSC=Err.AsStatus()
        set pResponse.Success=0
        set pResponse.ErrorMessage=$system.Status.GetErrorText(tSC)
    }
    Quit $$$OK
}
 

Hi Gadi,

The connection to the DB is done automatically by the adapter after you configure the BO settings. 

For example:

LDAP ServerSoraski.co.il
LDAP Port389
Distinguished NameOU=Users,OU=Accounts,DC=soraski,DC=co,DC=il

Here is a sample code for a method in a Business Operation that searches the LDAP DB:

The input accepts a filter (by which you want to search LDAP) and attributes (which attributes do you want returned. if no attributes are specified, all of the attributes are returned)

Method Search(pRequest As LDAP.REQ.Search, Output pResponse As LDAP.RES.Search) As %Status
{
    Set pResponse=##class(LDAP.RES.Search).%New()
    

     // sample data

    //set pRequest.Filter="cn=kerensk"
    //set pRequest.Attributes="sn,givenName"
    Set tSC=..Adapter.Search(.tEntries,2,pRequest.Filter,pRequest.Attributes,0) 
    if $$$ISERR(tSC) quit tSC
    if '$IsObject(tEntries) quit tSC
    

    Set count=0 
    do {   
        Set count=count+1  
        Set ent=tEntries.GetCurEntry()
        Set tRespEnt=##class(LDAP.RES.SearchEntry).%New()
        Set tRespEnt.DN=ent.DN
        Set attr="" ,str=""
        do { 
            Set attr=ent.Next(attr)  
            set str=str_","_attr
             Set valuelist=ent.GetAttribValue()                      
            Set valstr=""

           // go through the returned entries
            if valuelist'="" { 
                For i=1:1:valuelist.GetNumItems() {
                    Set valstr=valstr_",'"_valuelist.GetValue(i)_"'"
                } 
                Set valstr=$Extract(valstr,2,$Length(valstr))
                Do tRespEnt.Attributes.SetAt(valstr,attr)
            }
            else {
                set pResponse.Error="not found"
            }
        } while attr'=""
        Do pResponse.Entries.SetAt(tRespEnt,count)
    } while tEntries.NextEntry()
    $$$TRACE("Count of Entries: "_count)
    $$$TRACE(str)
    Quit tSC
}
 

Keren.