+ Start a Discussion

query Picklist in Flex

Hello all here´s a newbie question :smileyhappy: ..., can anyone give me an example of how to get the values from a picklist using Flex Biulder 2?
thnx in advance!
You need to call the DescribeSObject method to get the picklist values defined for a field. 
Thnx for the response!

I haven't found much info about this DescribeSObject but this is what i have so far

private function describe_Type():void{
                    new AsyncResponder(describeCallback, genericFault));                 
private function describeCallback(result: Object):void{
                      ta.text = 'describe Result\n' + ObjectUtil.toString(result);

at runtime this displays all the info about the Product2 and i can see the picklist values but this is a string.

do you know how or do you have an example of how could i have access to the values of the picklist?

thnx again!

It's actually a string that represent both the data and the structure of the object that you are "toStringing". 

You should be able to obtain a describeSObjectResult (dsr) and do something similar to the following

for (var i:int = 0; i<dsr.fields.length;i++) {
    var field:Object = drs.fields[i];
    if (field.type == "picklist") {
        for (var j:int = 0;j<field.picklistValues.length;j++) {
            var entry:Object = field.picklistValues[j];
            trace("value: " + entry.value);
            trace("label: " + entry.label);
            trace("is default: " + entry.defaultValue);
            trace("is active: " + etnry.active);

The outer for MIGHT be traversed by using
for (var fieldName:String in dsr.fields) {


Building on the salesforce.mxml sample:


private function describeSObjects():void {
   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 (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";
    } // it's a picklist value
    ta.text += 'type = ' + describeSObjectResult.fields[fld_name].type + '\n';


Be sure to change the type you're interested in in the first function.
I'm glad I found this post... I was having no luck at all traversing the fields in my describe results.  The "for (var fld_name:String in describeSObjectResult.fields )" loop format worked like a charm.
Thanks guys.