Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursion

Status
Not open for further replies.

Signit

MIS
Oct 17, 2003
114
0
0
US
I have written a ColdFusion component to interact through LDAP with Active Directory. The component is working great and I am getting the functionality I need from it.

However, I am building an additional method by which I plan to enumerate all of the OU objects in AD. While I recursively move through each OU object and its sub objects building a hierarchy my code is presently only returning a string. This string provides decent display information but is not interactive. My eventual goal is a completely interactive folder tree. I think an array of structures is probably where I need to go, but I am having a hard time thinking my way there as I am unfamiliar with structures.

I've attached my code and an example of the returned string. Let me know if I need to provide you with more information. Any help would be greatly appreciated.

my code
Code:
  <cffunction name="enumerateOU" returntype="string"
     displayname="Enumerate OU Objects"
     hint="recursively displays all container and organizationalUnit objects under a specified base">
    <cfargument name="base_ou" type="string" required="yes">
    <cfargument name="string_space" type="string" required="yes">
    <cfargument name="base_branch" type="string" required="yes">
    
    <cfset var results = "">
    <cfset var retVal = "">
    <cfset var currentRow = 0>
    
    <cfset sub_ou_results=application.ldapCFC.getObject('oneLevel',
                                                        'name,canonicalName,objectCategory',
                                                        '#base_ou#,DC=my,DC=organization,DC=org',
                                                        '(OU=*)',
                                                        'name',
                                                        'asc')>
    
    <cfloop query="sub_ou_results">
      <cfset currentRow = currentRow + 1>
      <cfset results = enumerateOU('OU=' & name & ',' & base_ou, string_space & '&nbsp;&nbsp;&nbsp;', base_branch & '.' & currentRow)>
      <cfset retVal = retVal & '<br>' & string_space & base_branch & '.' & currentRow & '&nbsp;' & name & results>
    </cfloop>
    <cfreturn retVal>
  </cffunction>

<cfset base_ou_results ="">

<cfset base_ou_results=application.ldapCFC.getObject('onelevel',
                                                     'name,canonicalName',
                                                     'DC=my,DC=organization,DC=org',
                                                     '(OU=*)',
                                                     'name',
                                                     'asc')>

<cfsetting requestTimeOut="500">
<cfset testEm = "">
<cfoutput query="base_ou_results">
  <br>#base_ou_results.CurrentRow#&nbsp;#name#
    <cfset testEm = enumerateOU('OU=' & name, '&nbsp;&nbsp;&nbsp;', base_ou_results.CurrentRow)>
  #testEm#
</cfoutput>

my output
Code:
1 Cip
   1.1 Cad
   1.2 Portable
   1.3 REX
      1.3.1 ChkOut
      1.3.2 Prod
   1.4 Sppa
   1.5 Test
      1.5.1 Testhierarchy
   1.6 WC
   1.7 XR

generated by testEm variable containing:
<br>&nbsp;&nbsp;&nbsp;1.1&nbsp;Cad<br>&nbsp;&nbsp;&nbsp;1.2&nbsp;Portable<br>&nbsp;&nbsp;&nbsp;1.3&nbsp;REX<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.3.1&nbsp;ChkOut<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.3.2&nbsp;Prod<br>&nbsp;&nbsp;&nbsp;1.4&nbsp;Sppa<br>&nbsp;&nbsp;&nbsp;1.5&nbsp;Test<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.5.1&nbsp;Testhierarchy<br>&nbsp;&nbsp;&nbsp;1.6&nbsp;WC<br>&nbsp;&nbsp;&nbsp;1.7&nbsp;XR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top