Using SFX Edinburgh, I have a form with a polymorphic field (WhatId) that references many objects. I would like to limit the objects that are available to reference to 5 specific ones for use on this form as the others don’t make sense for the user. With the custom field renderer feature turned on, I attempted to use some code found in an older community post ( Dynamically Control the WhatId reference field popup - Questions - Skuid Community) However the JS I used is throwing errors in the console (TypeError: skuid.ui.getFieldRenderer is not a function). This makes sense when reading through the docs for the current version. JS is not my strong suit however and was wondering if anyone has a sample snippet attempting to accomplish the same thing? The code I attempted to use below, Thanks!!
var targetObjects = ='Vehicles__c', 'Contact', 'Account', 'House__c', 'Area__c'];
var renderAsPicklist = false;
field = argumentst0];
var value = skuid.utils.decodeHTML(argumentst1]),
metadata = field.metadata,
$ = skuid.$;
var params = argumentst0], model = params.model,
row = params.row,
$ = skuid.$;
var updateFieldData = function(field, refLength) {
switch ( refLength) {
case "001": // Account
field.options.returnFields = =
{id: 'Id', showInSearchDialog: false},
{id: 'Name', showInSearchDialog: true},
];
field.options.searchTemplate = "{{Name}}";
break;
case "701": // Contact
field.options.returnFields = =
{id: 'Id', showInSearchDialog: false},
{id: 'Name', showInSearchDialog: true},
];
field.options.searchTemplate = "{{Name}}";
break;
case "006": // Vehicles
field.options.returnFields = =
{id: 'Id', showInSearchDialog: false},
{id: 'Name', showInSearchDialog: true},
];
field.options.searchTemplate = "{{Name}}";
break;
case "a2c": // House
field.options.returnFields = =
{id: 'Id', showInSearchDialog: false},
{id: 'Name', showInSearchDialog: true},
];
field.options.searchTemplate = "{{Name}}";
break;
case "a2m": // Area
field.options.returnFields = =
{id: 'Id', showInSearchDialog: false},
{id: 'Name', showInSearchDialog: true},
];
field.options.searchTemplate = "{{Name}}";
break;
}
};
if (field.mode == 'edit') {
// Limit the set of target objects
var targets = ,
uniqueTargets = {};
$.each(metadata.referenceTo,function(i,r) {
if (($.inArray(r.objectName,targetObjects) != -1) && (!uniqueTargetstr.objectName])) {
targets.push(r);
uniqueTargetstr.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;
}
}
skuid.ui.getFieldRenderer(field)dfield.mode]( field, value );
//skuid.ui.fieldRenderersrmetadata.displaytype]efield.mode](field,value);
var params = argumentst0],
model = params.model,
row = params.row,
$ = skuid.$;
var whatId = row.WhatId;
var refString = String(whatId);
var refLength = refString.substring(0, 3);
if ( refLength === 'und') refLength = "006";//default to Vehicles
$(field.element).find("select").bind("change", function(e) {
var val = $( "select option:selected" ).text();
if ( val.startsWith("Vehicles")) {
updateFieldData(field,"006");
} else if ( val.startsWith("Account")) {
updateFieldData(field,"001");
} else if ( val.startsWith("Contact")) {
updateFieldData(field,"701");
} else if ( val.startsWith("House")) {
updateFieldData(field,"a2C");
} else if ( val.startsWith("Area")) {
updateFieldData(field,"a2m");
}
});
updateFieldData(field, refLength);