RecordType context for Table Filter

Thought this might be helpful for folks. This is a snippet that you can use on tables to limit the values of a picklist field to the permitted ones for a selected Record type. Skuid tables don’t have record context, so the default behavior is to display all picklist values for a field in the filter. For more involved objects, this gets unwieldy.

The code here is an extension of this article: https://docs.skuid.com/latest/en/skuid/filters/snippet-as-item-source.html and the setup of the page (and the logic) is pretty similar to how it’s described in the article. A model condition driving the table needs to work off the RecordTypeId and only works with a condition where the operator is “=” (No multiple values allowed in the condition). We use “Field from another model” for the condition and that one looks up the RecordType object which is either accepting a parameter fed into it or setting the DeveloperName to pull the recordType as well as an SObject condition. If the filter is inactivated, all values for the picklist are populated.

This snippet is a bit more dynamic and both the lookup field and the logic to sort out the sObject information are passed in as a parameter from the filter. It will also find the condition for the record type based on the condition filtering the RecordTypeId field, so you don’t need to to worry about naming conventions on the condition. This means you can use this piece of code for any picklist on any object where RecordTypes are in play.

If anyone has an easier approach or improvements, much appreciated. Here’s the code snippet and I’ll post a sample page in a comment here.

var f = arguments[0],
$ = skuid.$;
m = f.model;
o = m.objectName;
fld = f.list.filterCondition.field;
filterItems = ;

$.each(m.conditions,function(a,b){
if(b.field == ‘RecordTypeId’ && b.inactive === false && b.operator == ‘=’){
rt = b.value;
d = skuid.utils.getAPIDescribeLayout(o);
$.each(d.recordTypeMappings,function(e,rtm){
if(rtm.recordTypeId == rt){
$.each(rtm.picklistsForRecordType,function(f,pl){
if(pl.picklistName == fld){
$.each(pl.picklistValues, function(g,pv){
if(pv.active === ‘true’){
lab = pv.label;
val = pv.value;
filterItems.push({label: lab,value: val});
}

                   });  
               }  
           });  
       }  
   });             

}

if(b.field == ‘RecordTypeId’ && b.inactive === true){
obj = skuid.utils.getAPIDescribeSObject(o);
$.each(obj.fields, function(e,f){
if(f.name == fld){
$.each(f.picklistValues,function(g,pv){
if(pv.active === ‘true’){
lab = pv.label;
val = pv.value;
filterItems.push({label: lab,value: val});
}
});
}
});
}

});

return filterItems;

Here’s a simple sample page to see how this works in operation. This is off the Task Object and doesn’t have any custom references so you should be able to just drop it in to play with it. Note that there’s no change to the javascript from the first post where I pulled it from an opportunity page.

One quick point of clarity from the original post. You don’t actually need a dedicated model for the RecordType. This example uses an auto generated condition from a table filter for selecting the RecordType. Skuid already does a good job of generating this filter, so no reason to over-complicate it if you don’t have to.

Assigned Related To Who Record Type var f = arguments[0], $ = skuid.$; m = f.model; o = m.objectName; fld = f.list.filterCondition.field; filterItems = [];

$.each(m.conditions,function(a,b){
if(b.field == ‘RecordTypeId’ && b.inactive === false && b.operator == ‘=’){
rt = b.value;
d = skuid.utils.getAPIDescribeLayout(o);
$.each(d.recordTypeMappings,function(e,rtm){
if(rtm.recordTypeId == rt){
$.each(rtm.picklistsForRecordType,function(f,pl){
if(pl.picklistName == fld){
$.each(pl.picklistValues, function(g,pv){
if(pv.active === ‘true’){
lab = pv.label;
val = pv.value;
filterItems.push({label: lab,value: val});
}

                   });
               }
           });
       }
   });           

}

if(b.field == ‘RecordTypeId’ && b.inactive === true){
obj = skuid.utils.getAPIDescribeSObject(o);
$.each(obj.fields, function(e,f){
if(f.name == fld){
$.each(f.picklistValues,function(g,pv){
if(pv.active === ‘true’){
lab = pv.label;
val = pv.value;
filterItems.push({label: lab,value: val});
}
});
}
});
}

});

return filterItems;







I know it’s been a while, but I’m trying to do this and failing. It seems that skuid.utils.getAPIDescribeSOject and skuid.utils.getAPIDescribeLayout are no longer supported functions since they aren’t in any documentation I can find and seem to return null with any parameter I give them.

Is this correct?

Is there another workaround for dependant picklist and filters?