You need to sign in to do that
Don't have an account?
ekm
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"/>
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"/>
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
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}"
/>
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}"
/>
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.