10 Replies Latest reply on May 6, 2010 6:35 AM by kenji776

    Simply not smart enough to write this

    kenji776 Level 1

      Hey All,

      You know when you want to do something, and you realize you simply do not have the brain power to pull it off? I am there, but I think maybe a little bit of help might get me over the really hard part.

       

      GOAL: Pull scheme data from our Salesforce.com instance (a massive CRM platform, basically just a fancy relational database system). Find all related objects, parse the data, and feed it into the JIT javascript visulization framework (http://thejit.org/). I want to use CF to pull the data, parse it, and feed it to JIT, however the format JIT requires is hard for me to write programatically.

       

      Here is an example of the what the final result will look like, instead of numbers each node would be an object name.
      http://thejit.org/Jit/Examples/Spacetree/example2.html

       

      Here is the data that powers that thing.

      http://pastebin.com/n2Sv64M6

       

      It's just JSON, but the nesting get's really brutal.

      So far I have the code in place to get the data I want, and break it into chunks, but I can't think of an eloquent way to create the required JSON. Here is what I have so far.

       

      http://portal.fpitesters.com/sfmap.cfm

       

      Here is the code for that tool.

      <cfsetting requesttimeout="5000">
      
      <cfif isdefined("form.Flush")>
           <cfcache action="flush" >
      </cfif>
      
      <form name="FlushForm" method="post">
           <input name="Flush" value="Recalculate Relationships (Will Take a Long Time)" type="submit" />
      </form>
      
      <cfcache action="optimal">
      
      <cfoutput>
           These results where cached at #TimeFormat(Now())#.
           <cfset GlobalObject = server.OSF.describeGlobal()>
           <cfloop from="1" to="#arraylen(GlobalObject.Results)#" index="ObjectIndex">
                <cfset Object = server.OSF.describeObject(GlobalObject.Results[ObjectIndex])>
                <cfset ObjectInfo = Object.RawSoap>
                <cfset returnStruct = structnew()>
                
                <cfset RelationShips[GlobalObject.Results[ObjectIndex]] = arraynew(1)>
                <cfset numRefFields = 0>
                
                <cfloop
                     From="1"
                     To="#arraylen(ObjectInfo.Envelope.Body.describeSobjectResponse.result.fields)#"
                     Index="i">
                     
                     <cfset ObjectFieldReference = ObjectInfo.Envelope.Body.describeSobjectResponse.result.fields[i]>
                     
                     <cfif ObjectFieldReference.type.xmltext eq "reference">
                          <cfset numRefFields = numRefFields + 1>
                          <cfset RelationShips[GlobalObject.Results[ObjectIndex]][numRefFields] = structnew()>
                          <cfset RelationShips[GlobalObject.Results[ObjectIndex]][numRefFields].name=ObjectFieldReference.name.xmltext>
                          <cfset RelationShips[GlobalObject.Results[ObjectIndex]][numRefFields].label=ObjectFieldReference.label.xmltext>
                          <cfset RelationShips[GlobalObject.Results[ObjectIndex]][numRefFields].refto=ObjectFieldReference.referenceto.xmltext>
                     </cfif>
                     
                </cfloop>
                <a name="#GlobalObject.Results[ObjectIndex]#">RelationsShips in #GlobalObject.Results[ObjectIndex]#</a>
                <ol>
                     <cfloop from="1" to="#arraylen(RelationShips[GlobalObject.Results[ObjectIndex]])#" index="relationshipFieldIndex">
                          <li>  #RelationShips[GlobalObject.Results[ObjectIndex]][relationshipFieldIndex].name# to <a href="###RelationShips[GlobalObject.Results[ObjectIndex]][relationshipFieldIndex].refto#">#RelationShips[GlobalObject.Results[ObjectIndex]][relationshipFieldIndex].refto#</a></li>
                     </cfloop>
                </ol>
           </cfloop>
      </cfoutput>
      

       

       

      So instead of creating that simple dumb list, I ned to create the JSON, but how? I just can't wrap my brain around it for some reason. Any help, sample code, anything would be of use. Thank you.

        • 1. Re: Simply not smart enough to write this
          Adam Cameron. Level 5

          You know you can convert CF data structures to JSON with a single function call, right?

           

          http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-79 fa.html

           

          --

          Adam

          • 2. Re: Simply not smart enough to write this
            kenji776 Level 1

            I am familiar with that function. Maybe I'm overcomplicating things, but I don't think thats going to give the data in quite the structure I need. Worth a shot though. I'll try it out.

            • 3. Re: Simply not smart enough to write this
              Adam Cameron. Level 5

              JSON is JSON: it's a notation used to represent the structure of data, not a data structure unto itself.  It's up to you to structure the source data appropriately.

               

              You seem to have a lot of code already for something that's not working, and trying to get all that working will probably do your head in (a case in point: I'm not even prepared to look at that much code when someone is asking for help on these forums).  Can I recommend you ignore you actual data whilst you get this working, and just do a proof of concept work: use minimalist mock data to come up with a small working sample.  Once you get that formatted correctly, start thinking about expanding it to meet your needs; making sure the end result stays valid at intermediary stages.  Don't try to solve the whole thing at once.

               

              --

              Adam

              • 4. Re: Simply not smart enough to write this
                kenji776 Level 1

                You were right, it's definitly getting me close. You can see what I'm getting here.

                 

                http://portal.fpitesters.com/test.cfm

                 

                however compare the generated JSON

                 

                http://pastebin.com/zV7f0vNp

                 

                to the provided JSON

                 

                http://pastebin.com/n2Sv64M6

                 

                What is the deal with the differences? His doesn't have quotes, mine does, his has brackets for empty data, I had to manually type them in. His first node comes right after the inital { where as mine opens with { [. Am I going to have to do a bunch of manual cleanup, or am I just approaching this the wrong way? Here is my updated code.

                 

                <!--- With lots of objects this can take a while ---->
                <cfsetting requesttimeout="5000">
                
                <cfoutput>
                     <!--- Get a list of all the objects in Salesforce, delivered as a structure with an array inside (success and results keys) --->
                     <cfset GlobalObject = server.OSF.describeGlobal()>
                     
                     <!--- Create an array to hold all the object data to be converted to JSON later --->
                     <cfset ObjectsArray = arraynew(1)>
                     
                     <!--- Loop over the first 10 objects (just to make it faster for testing --->
                     <cfloop from="1" to="10" index="ObjectIndex">
                     
                          <!--- Get a listing of all the fields for this object. --->
                          <cfset Object = server.OSF.describeObject(GlobalObject.Results[ObjectIndex])>
                          
                          <!--- Grab the raw SOAP returned by the call --->
                          <cfset ObjectInfo = Object.RawSoap>
                          
                          <!--- Create a new entry in the object array. Create keys the id, name, data and children --->
                          <cfset ObjectsArray[ObjectIndex] = structnew()>
                          <cfset ObjectsArray[ObjectIndex].id = GlobalObject.Results[ObjectIndex]> 
                          <cfset ObjectsArray[ObjectIndex].name = GlobalObject.Results[ObjectIndex]> 
                          <cfset ObjectsArray[ObjectIndex].data = "{}">
                          <cfset ObjectsArray[ObjectIndex].children = arraynew(1)>
                           
                          <!--- a simple counter to track how many reference fields we find. there are lots of other kinds of fields we don't care about --->
                          <cfset numRefFields = 0>
                          
                          <!--- Loop over all the fields found in the SOAP data --->
                          <cfloop
                               From="1"
                               To="#arraylen(ObjectInfo.Envelope.Body.describeSobjectResponse.result.fields)#"
                               Index="i">
                               
                               <!--- Create a simple reference to this data --->
                               <cfset ObjectFieldReference = ObjectInfo.Envelope.Body.describeSobjectResponse.result.fields[i]>
                               
                               <!--- If the field type we are on is a reference type (a relationship to another object, then we need to further evaluate --->
                               <cfif ObjectFieldReference.type.xmltext eq "reference">
                                    <!--- we found another ref field, so increase our counter --->
                                    <cfset numRefFields = numRefFields + 1>
                                    
                                    <!--- Create a structure to hold the data for this child node --->
                                    <cfset ObjectsArray[ObjectIndex].children[numRefFields] = structnew()>
                                    
                                    <!--- populate the name, id, data, and children of this node. We shouldn't need to populate the children, because anything
                                           references in this node, should have a node somewhere else. We just link to that other node, creating a nice recursive loop --->
                                    <cfset ObjectsArray[ObjectIndex].children[numRefFields].name = ObjectFieldReference.referenceto.xmltext>
                                    <cfset ObjectsArray[ObjectIndex].children[numRefFields].id = ObjectFieldReference.referenceto.xmltext>
                                    <cfset ObjectsArray[ObjectIndex].children[numRefFields].data = ObjectFieldReference.label.xmltext>
                                    <cfset ObjectsArray[ObjectIndex].children[numRefFields].children = "[]">                    
                                    
                               </cfif>
                               
                          </cfloop>
                
                     </cfloop>
                </cfoutput>
                
                
                <cfdump var="#ObjectsArray#">
                
                <cfdump var="#SerializeJSON(ObjectsArray)#">
                
                • 5. Re: Simply not smart enough to write this
                  Adam Cameron. Level 5

                  That second link was just a temporary one, which has since expired.

                   

                  Can't you just paste this stuff into the body of your response?

                   

                  --

                  Adam

                  • 6. Re: Simply not smart enough to write this
                    kenji776 Level 1

                    Sorry I didn't see your response post at first. You are right, I should start with a smaller data set, but it feels like with this project a small test case wouldn't really be translateable into an automatic version. My whole issue here is trying to create an automatic parser, I could hand write the JSON sure, but that doesn't get me much closer to my goaI. know JSON is just a data format, but I thought there were like... a lot of rules to follow as to how it was structured, it bothers me that it varies so widley between who writes it. Seriously though, thank you for your input. I would have been trying to create my own JSON builder had you not mentioned the serialize function. I knew it was there, but didn't for some reason think it would be flexible enough. It is however, getting me close i think. I might have to do some after the fact parsing, depening how picky JIT is, but it's better than nothing by a long shot.

                    • 7. Re: Simply not smart enough to write this
                      kenji776 Level 1

                      Ah, again sorry, we seem to be writting our posts at the same time.

                       

                      http://pastebin.com/0XPzWDHr

                       

                      Try that link. Thats what my formatted JSON ends up looking like.

                       

                      There, sorry, just didn't want to be making huge posts.

                       

                      My JSON

                       

                      [
                          {
                              "ID": "Account",
                              "DATA": "{}",
                              "CHILDREN": [
                                  {
                                      "ID": "Account",
                                      "DATA": "Master Record ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Account"
                                  },
                                  {
                                      "ID": "RecordType",
                                      "DATA": "Record Type ID",
                                      "CHILDREN": "[]",
                                      "NAME": "RecordType"
                                  },
                                  {
                                      "ID": "Account",
                                      "DATA": "Parent Account ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Account"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Owner ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Created By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Last Modified By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "Contact",
                                      "DATA": "Billing Contact",
                                      "CHILDREN": "[]",
                                      "NAME": "Contact"
                                  },
                                  {
                                      "ID": "Contact",
                                      "DATA": "Primary Org Contact",
                                      "CHILDREN": "[]",
                                      "NAME": "Contact"
                                  },
                                  {
                                      "ID": "Contact",
                                      "DATA": "Primary Household Contact",
                                      "CHILDREN": "[]",
                                      "NAME": "Contact"
                                  }
                              ],
                              "NAME": "Account"
                          },
                          {
                              "ID": "AccountContactRole",
                              "DATA": "{}",
                              "CHILDREN": [
                                  {
                                      "ID": "Account",
                                      "DATA": "Account ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Account"
                                  },
                                  {
                                      "ID": "Contact",
                                      "DATA": "Contact ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Contact"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Created By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Last Modified By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  }
                              ],
                              "NAME": "AccountContactRole"
                          },
                          {
                              "ID": "AccountHistory",
                              "DATA": "{}",
                              "CHILDREN": [
                                  {
                                      "ID": "Account",
                                      "DATA": "Account ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Account"
                                  },
                                  {
                                      "ID": "SelfServiceUser",
                                      "DATA": "Created By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "SelfServiceUser"
                                  }
                              ],
                              "NAME": "AccountHistory"
                          },
                          {
                              "ID": "AccountPartner",
                              "DATA": "{}",
                              "CHILDREN": [
                                  {
                                      "ID": "Account",
                                      "DATA": "Account ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Account"
                                  },
                                  {
                                      "ID": "Account",
                                      "DATA": "Account ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Account"
                                  },
                                  {
                                      "ID": "Opportunity",
                                      "DATA": "Bid ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Opportunity"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Created By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Last Modified By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  }
                              ],
                              "NAME": "AccountPartner"
                          },
                          {
                              "ID": "AccountShare",
                              "DATA": "{}",
                              "CHILDREN": [
                                  {
                                      "ID": "Account",
                                      "DATA": "Account ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Account"
                                  },
                                  {
                                      "ID": "Group",
                                      "DATA": "User\/Group ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Group"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Last Modified By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  }
                              ],
                              "NAME": "AccountShare"
                          },
                          {
                              "ID": "ActivityHistory",
                              "DATA": "{}",
                              "CHILDREN": [
                                  {
                                      "ID": "Account",
                                      "DATA": "Account ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Account"
                                  },
                                  {
                                      "ID": "Contact",
                                      "DATA": "Contact\/Lead ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Contact"
                                  },
                                  {
                                      "ID": "Admin_Projects__c",
                                      "DATA": "Bid\/Account ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Admin_Projects__c"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Assigned To ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Created By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Last Modified By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  }
                              ],
                              "NAME": "ActivityHistory"
                          },
                          {
                              "ID": "AdditionalNumber",
                              "DATA": "{}",
                              "CHILDREN": [
                                  {
                                      "ID": "CallCenter",
                                      "DATA": "Call Center ID",
                                      "CHILDREN": "[]",
                                      "NAME": "CallCenter"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Created By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Last Modified By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  }
                              ],
                              "NAME": "AdditionalNumber"
                          },
                          {
                              "ID": "Admin_Projects__c",
                              "DATA": "{}",
                              "CHILDREN": [
                                  {
                                      "ID": "Group",
                                      "DATA": "Owner ID",
                                      "CHILDREN": "[]",
                                      "NAME": "Group"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Created By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Last Modified By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Project Lead",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  }
                              ],
                              "NAME": "Admin_Projects__c"
                          },
                          {
                              "ID": "ApexClass",
                              "DATA": "{}",
                              "CHILDREN": [
                                  {
                                      "ID": "User",
                                      "DATA": "Created By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Last Modified By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  }
                              ],
                              "NAME": "ApexClass"
                          },
                          {
                              "ID": "ApexTrigger",
                              "DATA": "{}",
                              "CHILDREN": [
                                  {
                                      "ID": "User",
                                      "DATA": "Created By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  },
                                  {
                                      "ID": "User",
                                      "DATA": "Last Modified By ID",
                                      "CHILDREN": "[]",
                                      "NAME": "User"
                                  }
                              ],
                              "NAME": "ApexTrigger"
                          }
                      ]
                      

                       

                      Their JSON (a small sample anyway)

                      {
                          id: \"node02\",
                          name: \"0.2\",
                          data: {
                              
                          },
                          children: [
                              {
                                  id: \"node13\",
                                  name: \"1.3\",
                                  data: {
                                      
                                  },
                                  children: [
                                      {
                                          id: \"node24\",
                                          name: \"2.4\",
                                          data: {
                                              
                                          },
                                          children: [
                                              {
                                                  id: \"node35\",
                                                  name: \"3.5\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node46\",
                                                          name: \"4.6\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              },
                                              {
                                                  id: \"node37\",
                                                  name: \"3.7\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node48\",
                                                          name: \"4.8\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node49\",
                                                          name: \"4.9\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node410\",
                                                          name: \"4.10\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node411\",
                                                          name: \"4.11\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              },
                                              {
                                                  id: \"node312\",
                                                  name: \"3.12\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node413\",
                                                          name: \"4.13\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              },
                                              {
                                                  id: \"node314\",
                                                  name: \"3.14\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node415\",
                                                          name: \"4.15\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node416\",
                                                          name: \"4.16\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node417\",
                                                          name: \"4.17\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node418\",
                                                          name: \"4.18\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              },
                                              {
                                                  id: \"node319\",
                                                  name: \"3.19\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node420\",
                                                          name: \"4.20\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node421\",
                                                          name: \"4.21\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              }
                                          ]
                                      },
                                      {
                                          id: \"node222\",
                                          name: \"2.22\",
                                          data: {
                                              
                                          },
                                          children: [
                                              {
                                                  id: \"node323\",
                                                  name: \"3.23\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node424\",
                                                          name: \"4.24\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              }
                                          ]
                                      }
                                  ]
                              },
                              {
                                  id: \"node125\",
                                  name: \"1.25\",
                                  data: {
                                      
                                  },
                                  children: [
                                      {
                                          id: \"node226\",
                                          name: \"2.26\",
                                          data: {
                                              
                                          },
                                          children: [
                                              {
                                                  id: \"node327\",
                                                  name: \"3.27\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node428\",
                                                          name: \"4.28\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node429\",
                                                          name: \"4.29\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              },
                                              {
                                                  id: \"node330\",
                                                  name: \"3.30\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node431\",
                                                          name: \"4.31\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              },
                                              {
                                                  id: \"node332\",
                                                  name: \"3.32\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node433\",
                                                          name: \"4.33\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node434\",
                                                          name: \"4.34\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node435\",
                                                          name: \"4.35\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node436\",
                                                          name: \"4.36\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              }
                                          ]
                                      },
                                      {
                                          id: \"node237\",
                                          name: \"2.37\",
                                          data: {
                                              
                                          },
                                          children: [
                                              {
                                                  id: \"node338\",
                                                  name: \"3.38\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node439\",
                                                          name: \"4.39\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node440\",
                                                          name: \"4.40\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node441\",
                                                          name: \"4.41\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              },
                                              {
                                                  id: \"node342\",
                                                  name: \"3.42\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node443\",
                                                          name: \"4.43\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              },
                                              {
                                                  id: \"node344\",
                                                  name: \"3.44\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node445\",
                                                          name: \"4.45\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node446\",
                                                          name: \"4.46\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node447\",
                                                          name: \"4.47\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              },
                                              {
                                                  id: \"node348\",
                                                  name: \"3.48\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node449\",
                                                          name: \"4.49\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node450\",
                                                          name: \"4.50\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node451\",
                                                          name: \"4.51\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node452\",
                                                          name: \"4.52\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node453\",
                                                          name: \"4.53\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              },
                                              {
                                                  id: \"node354\",
                                                  name: \"3.54\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node455\",
                                                          name: \"4.55\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node456\",
                                                          name: \"4.56\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node457\",
                                                          name: \"4.57\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              }
                                          ]
                                      },
                                      {
                                          id: \"node258\",
                                          name: \"2.58\",
                                          data: {
                                              
                                          },
                                          children: [
                                              {
                                                  id: \"node359\",
                                                  name: \"3.59\",
                                                  data: {
                                                      
                                                  },
                                                  children: [
                                                      {
                                                          id: \"node460\",
                                                          name: \"4.60\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node461\",
                                                          name: \"4.61\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node462\",
                                                          name: \"4.62\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node463\",
                                                          name: \"4.63\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      },
                                                      {
                                                          id: \"node464\",
                                                          name: \"4.64\",
                                                          data: {
                                                              
                                                          },
                                                          children: [
                                                              
                                                          ]
                                                      }
                                                  ]
                                              }
                                          ]
                                      }
                                  ]
                              },
                              {
                                  id: \"node165\",
                                  name: \"1.65\",
                                  data: {
                                      
                                  },
                                  children: [
                                      {
                                          id: \"node266\",
                                          name: \"2.66\",
                                          data: {
                                              
                                          },
                                          children: [
                      
                      • 8. Re: Simply not smart enough to write this
                        kenji776 Level 1

                        Well I am very close, my demo loads, but I'd just displays the same children over and over again. I'm sure its a structural problem in my JSON, but I can't exactly figure out. It seems I need to nest the children further, but I'm not sure why or how much further until it becomes infinitly recursive like I want.

                         

                        I know this isn't really a CF problem anymore, but the support group for this framework blows, and you guys are the smartest coders I know

                        Any help is appreciated, thanks.

                         

                        Here is a link to the demo

                        http://portal.fpitesters.com/sfmap/example2.html

                         

                        Here is the JSON that mostly works.

                        {
                            id: "account",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "account",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "account"
                                },
                                {
                                    id: "recordtype",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "recordtype"
                                },
                                {
                                    id: "account",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "account"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "contact",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "contact"
                                },
                                {
                                    id: "contact",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "contact"
                                },
                                {
                                    id: "contact",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "contact"
                                }
                            ],
                            name: "account"
                        },
                        {
                            id: "accountcontactrole",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "account",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "account"
                                },
                                {
                                    id: "contact",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "contact"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                }
                            ],
                            name: "accountcontactrole"
                        },
                        {
                            id: "accounthistory",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "account",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "account"
                                },
                                {
                                    id: "selfserviceuser",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "selfserviceuser"
                                }
                            ],
                            name: "accounthistory"
                        },
                        {
                            id: "accountpartner",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "account",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "account"
                                },
                                {
                                    id: "account",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "account"
                                },
                                {
                                    id: "opportunity",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "opportunity"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                }
                            ],
                            name: "accountpartner"
                        },
                        {
                            id: "accountshare",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "account",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "account"
                                },
                                {
                                    id: "group",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "group"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                }
                            ],
                            name: "accountshare"
                        },
                        {
                            id: "activityhistory",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "account",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "account"
                                },
                                {
                                    id: "contact",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "contact"
                                },
                                {
                                    id: "admin_projects__c",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "admin_projects__c"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                }
                            ],
                            name: "activityhistory"
                        },
                        {
                            id: "additionalnumber",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "callcenter",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "callcenter"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                }
                            ],
                            name: "additionalnumber"
                        },
                        {
                            id: "admin_projects__c",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "group",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "group"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                }
                            ],
                            name: "admin_projects__c"
                        },
                        {
                            id: "apexclass",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                }
                            ],
                            name: "apexclass"
                        },
                        {
                            id: "apextrigger",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                }
                            ],
                            name: "apextrigger"
                        },
                        {
                            id: "approval",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "contract",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "contract"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                }
                            ],
                            name: "approval"
                        },
                        {
                            id: "asset",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "contact",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "contact"
                                },
                                {
                                    id: "account",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "account"
                                },
                                {
                                    id: "product2",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "product2"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                }
                            ],
                            name: "asset"
                        },
                        {
                            id: "assignmentrule",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                }
                            ],
                            name: "assignmentrule"
                        },
                        {
                            id: "attachment",
                            data: {
                                
                            },
                            children: [
                                {
                                    id: "account",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "account"
                                },
                                {
                                    id: "user",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "user"
                                },
                                {
                                    id: "selfserviceuser",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "selfserviceuser"
                                },
                                {
                                    id: "selfserviceuser",
                                    data: {
                                        
                                    },
                                    children: [
                                        
                                    ],
                                    name: "selfserviceuser"
                                }
                            ],
                            name: "attachment"
                        }
                        
                        • 9. Re: Simply not smart enough to write this
                          Adam Cameron. Level 5

                          Right.  Busy w/end, sorry.

                           

                          The problem is that the top level of the data structure they want is a struct, and you're creating an array.  In JSON notation {} denotes a struct, [] denotes an array.

                           

                          Also their structure is hierarchical, however I see nothing in your code (like a recursive call) which would effect a hierarchy.  You're just creating a flat array.

                           

                          --

                          Adam

                          • 10. Re: Simply not smart enough to write this
                            kenji776 Level 1

                            Hey Adam,

                            Thanks for the help. Looking at this framework closer, I don't think it's going to do what I want it to to. I noticed when it hits the end of the heirachy, it just resets to the same root node that you started from. I needed it to load the root node that has the same name/id as the node you just clicked on, hence creating a recursive type hierarchy. I got the JSON pretty much figured out, but even then it doesn't perform as desired. I think my next best bet is to create some kind of simple AJAX based crawler. The visualizations in this are nice, but I don't think it works like I want it to. If you think I'm wrong, certainly let me know, but otherwise I'm going to start working on rolling my own basic visualizer system.