function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jgrenfelljgrenfell 

Flex DataGrid Issue Displaying fields from a related object

I have a simple Datagrid in Flex:
Code:
<mx:DataGrid id="dg_sites" width="475" height="300" editable="false">
    <mx:columns>
     <mx:DataGridColumn headerText="Id" dataField="Id" visible="false"/>
     <mx:DataGridColumn headerText="Borough" dataField="Site__r.Borough__c"/>
     <mx:DataGridColumn headerText="Name" width="200" dataField="Name"/>
     <mx:DataGridColumn headerText="Available Slots" width="90" dataField="Available_Slots__c"/>
     <mx:DataGridColumn headerText="Business Group" dataField="Business_Group_Site__c" visible="false"/>
    </mx:columns>
    </mx:DataGrid>

And a SoQL query that I use to populate it:
Select Start__c, Shift__c, Name, Id, End__c, Business_Group_Site__c, Available_Slots__c, Site__r.Borough__c From Site_Log__c WHERE Start__c > TODAY AND Shift__c = 'Day'
 
All of the columns populate correctly except the Site__r.Borough.  I've tried changing the dataField to just "Borough__c", but it still ends up blank.  The SoQL definitely returns values for that field.  Has anyone tried this, any ideas?

Best Answer chosen by Admin (Salesforce Developers) 
jgrenfelljgrenfell
I figured out a workaround for this, but if anyone has anything more simple, let me know.  It's definitely the period in the Datafield name that causes the problem.  So when I return the data from Salesforce, I loop through it and assign it to a new array with a different name.  I figure someone else might hit the same thing so here's the code I used:
Code:
apex.execute("clsTransitionalJobs", "GetUpcomingSites", params,
     new AsyncResponder(
         function (qr:ArrayCollection):void   //ar:ArrayCollection
            {
                var ar:ArrayCollection = new ArrayCollection();
                var i:int;
                for (i = 0; i < qr.length; i++){
                //for (var j:int=0;j<qr.records.length;j++  ) {
                  ar.addItem( {Id:qr.getItemAt(i).Id, Name:qr.getItemAt(i).Name,
                  Business_Group_Site__c:qr.getItemAt(i).Business_Group_Site__c, 
        Available_Slots__c:qr.getItemAt(i).Available_Slots__c, 
        Site__c:qr.getItemAt(i).Site__c, 
        Borough__c:qr.getItemAt(i).Site__r.Borough__c});
                }
               // dg_sites.columns = [new DataGridColumn('Id'), new DataGridColumn('Site__r.Borough__c'),
                //new DataGridColumn('Name'), new DataGridColumn('Available_Slots__c'), new DataGridColumn('Business_Group_Site__c')];
                dg_sites.dataProvider = ar;
            },
            function (fault:Object):void {
             Alert.show("Failed: "+ObjectUtil.toString(fault));
            })
        );
(I'm returning data from Apex code instead of a regular query because of a completely separate issue)
 

All Answers

jgrenfelljgrenfell
I figured out a workaround for this, but if anyone has anything more simple, let me know.  It's definitely the period in the Datafield name that causes the problem.  So when I return the data from Salesforce, I loop through it and assign it to a new array with a different name.  I figure someone else might hit the same thing so here's the code I used:
Code:
apex.execute("clsTransitionalJobs", "GetUpcomingSites", params,
     new AsyncResponder(
         function (qr:ArrayCollection):void   //ar:ArrayCollection
            {
                var ar:ArrayCollection = new ArrayCollection();
                var i:int;
                for (i = 0; i < qr.length; i++){
                //for (var j:int=0;j<qr.records.length;j++  ) {
                  ar.addItem( {Id:qr.getItemAt(i).Id, Name:qr.getItemAt(i).Name,
                  Business_Group_Site__c:qr.getItemAt(i).Business_Group_Site__c, 
        Available_Slots__c:qr.getItemAt(i).Available_Slots__c, 
        Site__c:qr.getItemAt(i).Site__c, 
        Borough__c:qr.getItemAt(i).Site__r.Borough__c});
                }
               // dg_sites.columns = [new DataGridColumn('Id'), new DataGridColumn('Site__r.Borough__c'),
                //new DataGridColumn('Name'), new DataGridColumn('Available_Slots__c'), new DataGridColumn('Business_Group_Site__c')];
                dg_sites.dataProvider = ar;
            },
            function (fault:Object):void {
             Alert.show("Failed: "+ObjectUtil.toString(fault));
            })
        );
(I'm returning data from Apex code instead of a regular query because of a completely separate issue)
 

This was selected as the best answer
kalyforminkalyformin

Thank you SO MUCH!  Your fix solved my day long problem

 

THANK YOU!!!