Filtered picklist values for a relatedto field

for a relatedTo(whatID) on task I want to allow a certain number of objects that the task can be related to. I found another snippet that allows me to set the target objects but I still want the autocomplete to work based on the target object the user has selected from the picklist. Essentially I want to work like the out of the box picklist renderer with autocomplete but with a defined set of target objects. // // CONFIGURATION // // Define the possible target objects var targetObjects = [‘Opportunity’,‘Account’,‘RPS_Business_Plan__c’]; // Render as a Picklist instead of an Autocomplete? var renderAsPicklist = false; var field = arguments[0], value = skuid.utils.decodeHTML(arguments[1]), metadata = field.metadata, $ = skuid.$; if (field.mode == ‘edit’) { field.options.type = ‘REFPICK’; // Limit the set of target objects var targets = [], uniqueTargets = {}; $.each(metadata.referenceTo,function(i,r){ if (($.inArray(r.objectName,targetObjects) != -1) && (!uniqueTargets[r.objectName])) { targets.push(r); uniqueTargets[r.objectName] = 1; if (targets.length == targetObjects.length) return false; } }); if (targets.length) { // Make this field render as a picklist? if (renderAsPicklist) field.options.type = ‘REFPICK’; // Override the current referenceTo metadata.referenceTo.length = 0; metadata.ref = $.map(targets,function(targ){return targ.objectName;}).join(); metadata.referenceTo = targets; } } // Run the standard renderer skuid.ui.fieldRenderers[metadata.displaytype]field.mode; field.options.type = ‘CUSTOM’;

I’m not exactly sure which part of this is not working for you, but what I’m hearing is that you are trying to have the renderer be “Auto-Complete” but with a defined, limited set of target objects. In that case, I think that you only need to change these lines: 

if (field.mode == ‘edit’) { 
field.options.type = ‘REFPICK’; 

to be:

if (field.mode == ‘edit’) { 
   if (renderAsPicklist) field.options.type = ‘REFPICK’; 

Zach…yes that’s right. But when I do that it does filter out the objects…but for the actual value it shows a dropdown list as opposed to the autocomplete where you could type in a value and have it search for a matching record.

Did you actually make the code change I provided? I just copied and pasted the code you provided above, made the change that I suggested, and it displays an autocomplete. Did you switch the field to use the Custom Field Renderer snippet?