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
roktechieroktechie 

Getting picklist values via describe call with AJAX toolkit

I am having a lot of trouble getting this to work.  The web services API docs say that field.picklistValues should return a PickListEntry array.  However, it appears that field.picklistValues has no properties.  Here is my full example.  Can anyone point out what I am doing wrong?  Thanks.

Code:
logDebug("---------- fields ---------");
for (var i=0; i<result.fields.length; i++) {
  var field = result.fields[i];
  logDebug(field.name + " : " + field.label + " : " + field.length + " : ");
  logDebug("-------------- picklist values --------");
  for (var x=0; x<5; x++) {
    var picklistValue = field.picklistValues[x];
    logDebug(picklistValue.label);
  }
}

 

cheenathcheenath
Not sure what is going wrong. Code below will help to figure out
what is going wrong:


logDebug("---------- fields ---------");
for (var i=0; i<result.getArray("fields").length; i++) {
var field = result.getArray("fields")[i];
logDebug(field.name + " : " + field.label + " : " + field.length + " : ");
logDebug("-------------- picklist values --------");

alert(field); //this will display all the fields in field.

for (var x=0; x<5; x++) {
var picklistValue = field.picklistValues[x];
logDebug(picklistValue.label);
}
}




roktechieroktechie
Thanks.  For the field in question, it returned this data.

picklistValues:{active:'true',
defaultValue:'false', label:'NIPS', value:'NIPS', },{active:'true',
defaultValue:'false', label:'HIPS', value:'HIPS', },{active:'true',
defaultValue:'false', label:'VA', value:'VA', },{active:'true',
defaultValue:'false', label:'MFW', value:'MFW', },

How do I use this array item? It doesn't appear to be another array. Do I need to run getArray on the picklistValues?
cheenathcheenath

var picklistValues = field.getArray("picklistValues");
for (var x=0; picklistValues.length; x++) {
var picklistValue = picklistValues[x];
logDebug(picklistValue.label);
}



Greg HGreg H
Here's a pretty clear example of getting picklist values:
-greg
roktechieroktechie
Thanks.  This worked perfectly.