Simply not smart enough to write this
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.
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>
<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.
