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
gokubigokubi 

Get StageNames for a single Opp record type?

I've got working code to give me all Opp stagenames. I would like to narrow that list to values appropriate to one record type. I wasn't able to find a path to that in the documentation about the describeSObjects call.

Here's the working code:

Code:
function generateStageNamePicklist(picklistid) {
 var objects = sforce.connection.describeSObjects(["Opportunity"]);
 var OppObject = objects[0];
 var OppSourcePicklistValues = new Array();
   
 for (var i=0; i<OppObject.fields.length; i++) {
  if(OppObject.fields[i].name=="StageName") {
   var StageNameField = OppObject.fields[i];
   StageNameFieldPicklistValues = StageNameField.picklistValues;
  }
 }
 SelectBox = "<select id='" + picklistid + "'>";
 for (var currentStageName=0;currentStageName<StageNameFieldPicklistValues.length;currentStageName++) {
  SelectBox +="<option value="+ StageNameFieldPicklistValues[currentStageName].value +">" + StageNameFieldPicklistValues[currentStageName].value + "</option>";
 }
 SelectBox +="</select>";
 return SelectBox;
}

 Thanks in advance for any help!

Steve

SuperfellSuperfell
Hey Steve, this data is available from the describeLayout call, you can pass your specific recordTypeId into the desribeLayout call as the 2nd parameter to limit the results to just the layout for that recordType. (see the PicklistForRecordType part of the layout result).
gokubigokubi
Thanks for the tip Simon! Here's my working code:

Code:
function generatePicklistArray(ObjectName,PicklistName,RecordType) {
 //array to hold picklist values
 var PicklistValues = new Array();
 //get the layout for the object and recordtype
 var result = sforce.connection.describeLayout(ObjectName,[RecordType]);
 //get mappings for this recordtype
 var mappings = result.getArray("recordTypeMappings");
 //get the first mapping
 var ThisMapping = mappings[0];
 //get all the picklists
 var Picklists = ThisMapping.picklistsForRecordType;
 //loop through them and get the values when you find the right one
 for (var i=0; i<Picklists.length; i++) {
  if(Picklists[i].picklistName==PicklistName) {
   PicklistValues = Picklists[i].picklistValues;
  }
 }
 return PicklistValues;
}