How to sort Opps in Chart by StageName as per order in Sales Process

  • 1
  • Idea
  • Updated 3 years ago
First off, it would be great if sorting of a table and chart can be set to the order of picklist values. The most obvious case of this is on the StageName field in Opportunities.

Here's a workaround snippet for the following use case:
Basic model on the Opportunities object which is then used in a Chart where {{StageName}} is used to split the values. Column Chart called "Opps by Qtr by Stage".



// this snippet has been created in order to sort the series in the chart by the stage order
// in the sales process assigned to the Record Type

var chartObj = arguments[0],
    Opportunities = skuid.$M('Opportunities'),
	sortedSeries= [],
	$ = skuid.$;
	// to get the sort order, we need to find the Stage field metadata in the Opportunities models list of fields
	$.each(Opportunities.fields, function(f,field){
	    if ( === "StageName"){
	        StageName = field;
	        return false;
	// now use this field to create a temporary array to replace the current series
	// loop through entries in order to then find the corresponding series by the same name
	// in order to add it to the temporary array
	$.each(StageName.picklistEntries, function(p,entry){
	    $.each(chartObj.series, function(s,series){
	        if ( === entry.label){
	// empty original series
	chartObj.series.length = 0;
	// insert sorted chart

Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 43,156 Points 20k badge 2x thumb

Posted 3 years ago

  • 1

Be the first to post a reply!