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
ekmekm 

Populating Flex ComboBox from picklist

Hi,

I'm attempting to populate a combobox from a picklist (Type) from the Event table using the describeSObject based on the salesforce.mxml example. I'm getting the values no problem, but am getting the good ole [object Object] in the combo box. I'm attempting to put the describeSObject into an arrayCollection (myPickList) and use the arraycollection as a dataprovider for the combobox.

Any suggestion for what I'm missing a better way to do this would be greatly appreciated.

Thanks,

private function describeSObjects():void {
         apex.describeSObjects(
         ["Event"],
           new AsyncResponder(describeSObjects_Test, genericFault));
    }
   
    private function describeSObjects_Test(result:Object):void
    {
         if (result != null)
         {
              var describeSObjectResult:DescribeSObjectResult = result[0] as DescribeSObjectResult;
             ta.text = 'describeSObjects_Test describeSObjectResult fields = \n';
              for (var fld_name:String in describeSObjectResult.fields )
              {
                var fieldName:String = describeSObjectResult.fields[fld_name].name;
                //ta.text += 'field = ' + fieldName + '\n';
                var fieldType:String = describeSObjectResult.fields[fld_name].type;
                if (fieldName == 'Type')
                {               
                if (fieldType == 'picklist')
                {
                      ta.text += '  Picklist values:' + '\n';
                      for (var j:int = 0;j<describeSObjectResult.fields[fld_name].picklistValues.length;j++)
                      {
                         ta.text += "    " + describeSObjectResult.fields[fld_name].picklistValues[j].value + "\n";
                  
                   
                         myPickList.addItem( {Type:describeSObjectResult.fields[fld_name].picklistValues[j].value } );
                         //cmbType[i] = [item.label];
                      }         
                }
                }
              
              }
         }
    }

<mx:ComboBox  id="cmbType"
            dataProvider="{myPickList}" rowCount="10"
            labelField="@Type"/>

Best Answer chosen by Admin (Salesforce Developers) 
ekmekm
Bingo. That basically did it. Thanks!
The working code is below for anyone interested.

    [Bindable]
    public var picklistValues:Array = new Array();
       
    [Bindable]
     public var foo:PickListEntry;
     
   
    public function describeSObjects():void {
   
    //var picklistValues:Array = new Array(); 
     var myPicklistValues:ArrayCollection = new ArrayCollection(); 
     apex.describeSObjects(["Event"], 
        new AsyncResponder(function (result:Object):void 
     { 
         myPicklistValues = result[0].fields.Type.picklistValues; 
         for (var p:int=0;p<myPicklistValues.length;p++) 
         { 
             if (myPicklistValues[p].active) 
             { 
                 var foo:PickListEntry = myPicklistValues[p].label;
                 picklistValues.push(foo);
                              } 
     }  
  
     }, genericFault));

    }

<mx:ComboBox  id="cmbType"
             rowCount="10"
             dataProvider="{picklistValues}"
            />

All Answers

ekmekm
Joe,

Thanks for providing your link. However, I'm still missing something.

When foo is created within the describeSObjects function and I attempt to make it the dataprovider for the combobox or even just populate foo in an Alert in another function, I receive the following compile error:
"access of undefined property foo"
I made foo public and Bindable and received the following:
"TypeError: Error #1034: Type Coercion failed: cannot
convert "Broker Training" to com.salesforce.results.PickListEntry." where Broker Training is the first value in the picklist I'm calling.

Thanks again for anyone's help on this.

Errol


/*
    [Bindable]
     public var foo:PickListEntry;
     */
   
    public function describeSObjects():void {
   
    var picklistValues:Array = new Array(); 
     var myPicklistValues:ArrayCollection = new ArrayCollection(); 
     apex.describeSObjects(["Event"], 
        new AsyncResponder(function (result:Object):void 
     { 
         myPicklistValues = result[0].fields.Type.picklistValues; 
         for (var p:int=0;p<myPicklistValues.length;p++) 
         { 
             if (myPicklistValues[p].active) 
             { 
                 var foo:PickListEntry = myPicklistValues[p].label;
                 //foo = myPicklistValues[p].label;
                 picklistValues.push(foo);
                 Alert.show("foo is " + foo);
                
             } 
     }  
  
     }, genericFault));

    }
   
<mx:ComboBox  id="cmbType"
             rowCount="10"
             dataProvider="{foo}"
            />
Joseph FerraroJoseph Ferraro
try setting the dataprovider of your combobox with {picklistValues}.
ekmekm
Bingo. That basically did it. Thanks!
The working code is below for anyone interested.

    [Bindable]
    public var picklistValues:Array = new Array();
       
    [Bindable]
     public var foo:PickListEntry;
     
   
    public function describeSObjects():void {
   
    //var picklistValues:Array = new Array(); 
     var myPicklistValues:ArrayCollection = new ArrayCollection(); 
     apex.describeSObjects(["Event"], 
        new AsyncResponder(function (result:Object):void 
     { 
         myPicklistValues = result[0].fields.Type.picklistValues; 
         for (var p:int=0;p<myPicklistValues.length;p++) 
         { 
             if (myPicklistValues[p].active) 
             { 
                 var foo:PickListEntry = myPicklistValues[p].label;
                 picklistValues.push(foo);
                              } 
     }  
  
     }, genericFault));

    }

<mx:ComboBox  id="cmbType"
             rowCount="10"
             dataProvider="{picklistValues}"
            />
This was selected as the best answer
gv007gv007

Hi am trying the example some of the componets am not able find in the libaras

 

 

exp: result.fields.Type to access this type what class i need to import .can you post all the libray files that will help me.